0

This is my code to store audio from Android app to server and database

include("db.php");
$uid=$_POST['uid'];
$meeting_id=$_POST['meeting_id'];
if(!is_dir("audioupload/".$uid."/".$_SESSION["uid"]."/"))   
    {
        mkdir("audioupload/".$uid."/".$_SESSION["uid"]."/");
    }
$info = pathinfo($_FILES['audio']['name']);
$ext = $info['extension'];
$audio_name = "meeting_id".$meeting_id.".".$ext;
if(move_uploaded_file($_FILES["audio"]["tmp_name"], "audioupload/".$uid."/".$_SESSION["uid"] ."/". $audio_name))
{
    echo "File uploaded Successfully";
} else
 {
   echo "File was not uploaded";
}
$sql="INSERT INTO `audio`(`uid`,`meeting_id`,`audio`) VALUES ('".$uid."','".$meeting_id."','".$audio_name."')";
$result1 = mysqli_query($conn,$sql);

This code is working fine. I'm able to store audios of particular user in their particular directories.

What I actually want that display this audio on front end

<td><audio id="audio" autoplay controls src="<?php echo $row_audio['audio'];?>" type="audio/mpeg"></audio></td>

This is what I'm using for fetch records, a simple while loop with php fetch_assoc

I get this basic response from database

image of audios on front side

How will I get audios that I store in server?

halfer
  • 19,824
  • 17
  • 99
  • 186
mahadev sutar
  • 171
  • 2
  • 16
  • 2
    Please don't use txt spk! Use proper grammar. – Styphon Jan 11 '17 at 10:51
  • have you tried that audio player working with static ..? – Mr world wide Jan 11 '17 at 10:51
  • please add a audio file here so we can be helpful – Sunil Verma Jan 11 '17 at 10:53
  • First of all, your code is not secure from SQL injections. You should use prepared statements. NEVER insert a `$_POST` directly in a query. (http://bobby-tables.com/) @SunilVerma I don't think you need the audiofile to solve the problem. What information you want to get from? – Twinfriends Jan 11 '17 at 10:56
  • I think the error is simply that in your HTML code you echo the `row_audio` thing, while this is not the path you want. You want to echo the `audioupload/".$uid."/".$_SESSION["uid"] ."/". $audio_name` and not only the audio_name. – Twinfriends Jan 11 '17 at 10:59
  • @Twinfriends i think you know its fairly simple to play the audio file nowadays http://www.w3schools.com/html/html5_audio.asp in case you dont. So if the audio format is not correct while saving it can be an issue. – Sunil Verma Jan 11 '17 at 11:00
  • Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Jan 11 '17 at 11:02
  • @Twinfriends your right bro. that's wt i exactly want to display but i dont know how to fetch records that are on server – mahadev sutar Jan 11 '17 at 11:08
  • @AbdulWaheed yup bro audio player is working in static. – mahadev sutar Jan 11 '17 at 11:09
  • Should be something like `` – Twinfriends Jan 11 '17 at 11:45
  • @Twinfriends thanks bro it works for me. – mahadev sutar Jan 12 '17 at 04:59

0 Answers0