Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading an audio recording to mysql and playing in website
    primarykey
    data
    text
    <p>I have an upload phone app that uploads either images or audio recordings. The image can be uploaded to a mysql database and displayed no problem in a webpage, The problem i am having is playing the audio on the webpage, i have tested the webpage by playing mp3 files i have placed in the database myself though the webpage. When i upload an mp3 file from the phone or emulator nothing plays. The database is populated with a file size and on the webpage a media player does load, but nothing plays</p> <p>Edit 1 Since writing this i have learnt that android records in .amr files and not .mp3 which i had been creating the file as. Since then i can play the file on my desktop using either quicktime or real player. When i attempt to play the file through a web browser i get a quicktime logo with a question mark in the middle. Below is my code for playing the file.</p> <pre><code>header('Content-type: audio/amr'); $query = mysql_query("SELECT * FROM media WHERE media_id= '$idd'"); $row = mysql_fetch_array($query); echo $row['file']; </code></pre> <p>Embed code where 110 is $idd in the above</p> <pre><code>&lt;object data="sound.php?id=110 width='391' height='298'"&gt; &lt;embed src='sound.php' width='391' height='298'&gt;&lt;/embed&gt;'ERROR' &lt;/object&gt; </code></pre> <p>Edit 2</p> <p>If i put the same file directly on my server and NOT in the database this code downloads the file</p> <pre><code>&lt;OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width="100" height="100"codebase='http://www.apple.com/qtactivex/qtplugin.cab'&gt; &lt;param name='src' value="apr.amr"&gt; &lt;param name='autoplay' value="true"&gt; &lt;param name='controller' value="true"&gt; &lt;param name='loop' value="true"&gt; &lt;EMBED src="apr.amr" width="100" height="100" autoplay="true" controller="true" loop="true" pluginspage='http://www.apple.com/quicktime/download/'&gt; &lt;/EMBED&gt; &lt;/OBJECT&gt; </code></pre> <p>Edit 3 upload code</p> <pre><code>if (isset($_FILES['image']) &amp;&amp; $_FILES['image']['size'] &gt; 0) { $size = $_FILES['image']['size']; $type = $_FILES['image']['type']; // Temporary file name stored on the server $tmpName = $_FILES['image']['tmp_name']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); fclose($fp); $data = addslashes($data); // Create the query and insert // into our database. $query = "INSERT INTO media"; $query .= "(file, file_size, file_type) VALUES ('$data','$size','$type')"; $results = mysql_query($query, $link); $mediaid = mysql_insert_id(); $gender = $_POST['gender']; $cat_id = $_POST['cat']; $name = $_POST['name']; $lat = $_POST['lat']; $lon = $_POST['lon']; $user = $_POST['user']; $query="INSERT INTO instance (name, gender, cat_id, lon, lat, user_id) VALUES ('$name', '$gender', '$cat_id', '$lon', '$lat', '$user')"; $result=mysql_query($query); $instanceid = mysql_insert_id(); $query4 = "INSERT INTO media_link"; $query4 .="(media_id, instance_id) Values ('$mediaid','$instanceid')"; $results4 = mysql_query($query4, $link); } // Close our MySQL Link mysql_close($link); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload