Forum Moderators: coopster

Message Too Old, No Replies

Putting Audio in a Database

How do I save audio in databases and tell computers to play the audio

         

MartinWeb

4:08 pm on Jun 24, 2007 (gmt 0)

10+ Year Member



How can I save my audio's location in the database and the code the webpage so when you click on the link it plays the audio file that is saved in the same row as the rest of the text?

mattclayb

4:26 pm on Jun 24, 2007 (gmt 0)

10+ Year Member



are you uploading the audio file through a page as well?

SixTimesEight

10:02 pm on Jun 24, 2007 (gmt 0)

10+ Year Member



If all of your audio files are in the same directory, I would store only the filename in your DB, hardcode the directory into your page and just print "$directory.$filename"

MartinWeb

1:03 am on Jun 25, 2007 (gmt 0)

10+ Year Member



Hi. For images you have to add the
 <img src 
at the begining and
 > 
at the end. What do you have to add to the <?php echo "$Whatever";?> at the begining and end to make it play audio?

SixTimesEight

1:09 am on Jun 25, 2007 (gmt 0)

10+ Year Member



Unless you plan on integrating a flash mp3 player into your website, then just use a normal link as if you were linking to another page. Most people have something installed that will play it automatically (WMP, Quicktime, Winamp, etc).

<?php
echo '<a href="http://yourwebsite.tld/files/mp3/'.$mp3filename.'" title="'.$mp3filename.'">'.$mp3filename.'</a>';
?>

Granted, everyone in the world will know where you store your mp3s on your server and may hotlink to them unless you deny hotlinking.

MartinWeb

2:06 am on Jun 25, 2007 (gmt 0)

10+ Year Member


I tried your code but nothing happened.

phparion

4:52 am on Jun 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



nothing happened means? check your mp3 or audio file path it must be correct. try to print your href value and check its actual shape that will give you a quick hint about your mistake.

btw if you do not want your users to see your actual audio files folder, so that they can MISUSE your server resources e.g linking to your audio files directly from their websites wasting your bandwidth etc etc, then use a flash player you can download one for free from FlashKit.com movies section there are many free contributed by members or you can develop your own.

the idea will be to load audio files in the flash player in real time from the audio folder, block direct access to that folder and hot-linking too.

MartinWeb

1:50 am on Jun 26, 2007 (gmt 0)

10+ Year Member



I am new to php and I don't get what you said.

[edited by: MartinWeb at 1:51 am (utc) on June 26, 2007]

theistand

4:40 am on Jun 27, 2007 (gmt 0)

10+ Year Member



what is the code you are using? please post... I believe what phparion is saying is this... (btw props on the response to help someone secure their site phparion!)
all you need to do to link a file is create a normal link (even inside the php tags, but you have to use \" to get the quote character to show in an echo statement.)

ie <a href="folder1/folder2/nameOfFile.extension"></a> However with php you can type
<?php echo "<a href=\"folder1/folder2/".$variableOfFileLocation."\"></a>"
?>

or even

<a href="folder1/folder2/<?php echo $row_database['fileLocation'];?>"></a>

Of coures you have to create a mysql query and define the variable that calls the filelocation....

If you can post the code you are currently using, I think it would help the explination so we can use your code as the example...

tim

SixTimesEight

11:45 am on Jun 27, 2007 (gmt 0)

10+ Year Member



> but you have to use \" to get the quote character to show in an echo statement.

Not true. Using the code I gave, which surrounded the statement in 'single quotes', you don't have to slash the "double quotes". You would have to slash 'single quotes' if there were any in the statement though.

FYI: Any time you enclose a statement in double quotes in php, your telling php "there may be variables in this statement so look closely while you parse through here". It can be inefficient.

phparion

11:50 am on Jun 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



the parsing time difference of single and double quote is just negligible so you can use both without bothering about parsing time.

the double quotes are even better because single quotes do no support few things for instance all escape characters

[reason=typos]

theistand

12:23 pm on Jun 27, 2007 (gmt 0)

10+ Year Member



single or a double?

Give me a double!

[;o)

p.s. i usually stick with double so I don't screw stuff up... the A.D.D. is murder!