Code for uploading and previewing an audio file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eatspinach
Forum Newbie
Posts: 20
Joined: Mon Apr 20, 2009 8:50 am

Code for uploading and previewing an audio file?

Post by eatspinach »

does anyone know where i might find a good tutorial on uploading and previewing an audio file.

i need to somehow keep the file in the database not sure if this is possible, i have never attempted anyhing like this before so i would love any help or advice on the topic.

so far i have written this code (not a lot but gives you the idea of what i am trying to achieve)

Code: Select all

 
<?php
 
    if (isset($_POST['uploadBtn'])) 
    {
        //save the mp3 or wav to the database
    }
    
    if (isset($_POST['playBtn'])) 
    {
        //play back the audio file that has just been uploaded
    }
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Play some Audio</title>
</head>
<body>
  <div style="margin:auto; width:50%;">
    <fieldset style="border:1px solid #7f9db9;">
      <legend>Upload Audio</legend>
      <input name="uploadBtn" type="file" />
      <input name="playBtn" value="Play" type="button"  />
    </fieldset>
  </div>
</body>
</html>
 
Thanks for your help in advance,
Dave
Last edited by Benjamin on Mon Jun 08, 2009 10:36 am, edited 1 time in total.
Reason: Changed code type from text to php.
jmyeom
Forum Newbie
Posts: 8
Joined: Mon Jun 08, 2009 11:30 am

Re: Code for uploading and previewing an audio file?

Post by jmyeom »

... so you want to upload a play...?...


would you not upload using a save file script....(got it somewhere... ill dig it out for you!)
then when the page redirects after the upload, do a open file?....(easy to do :P)
then on page close = delete file from server?
eatspinach
Forum Newbie
Posts: 20
Joined: Mon Apr 20, 2009 8:50 am

Re: Code for uploading and previewing an audio file?

Post by eatspinach »

Well i guess the best way to do this would be that then the user hits play it plays the audio file that has been selected with the browse button.

Then when the form submit button is pressed the file is uploaded as a blob to the database, i have no idea how to do this so i would appreciate any help or direction.

Thanks,
Dave
Post Reply