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
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.
header('Content-type: audio/amr');
$query = mysql_query("SELECT * FROM media WHERE media_id= '$idd'");
$row = mysql_fetch_array($query);
echo $row['file'];
Embed code where 110 is $idd in the above
<object data="sound.php?id=110 width='391' height='298'"> <embed src='sound.php' width='391' height='298'></embed>'ERROR' </object>
Edit 2
If i put the same file directly on my server and NOT in the database this code downloads the file
<OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width="100" height="100"codebase='http://www.apple.com/qtactivex/qtplugin.cab'>
<param name='src' value="apr.amr">
<param name='autoplay' value="true">
<param name='controller' value="true">
<param name='loop' value="true">
<EMBED src="apr.amr" width="100" height="100" autoplay="true" controller="true" loop="true" pluginspage='http://www.apple.com/quicktime/download/'>
</EMBED>
</OBJECT>
Edit 3 upload code
if (isset($_FILES['image']) && $_FILES['image']['size'] > 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);
?>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…