aej1973
asked on
open a blob file php/mysql...
Hi, I have a BLOB file in my data base which is a voice file. From phpmyadmin if I click on this file I can open it and hear the contents. How do I open this file and listen to it using php? I have attached the code I am using to try and accomplish this. Thank you.
A
voicemail.php
A
voicemail.php
Tell us a little more about the "file" which is really a column in a data base, right? Where does it come from, etc?
ASKER
Ray, the voice file is stored on the server at /var/spool/test/voicemails .
OK, that's a start. Where does it come from, etc? Tell us the format of the file. What happens when you create a link to such a file and click the link? Can the file play in HTML5? Does it require a browser plug-in? Anything more you can share with us will be most helpful!
ASKER
When I click on the link on the php file I see gibberish as follows:
RIFF¤WAVEfmt @€>data€ðÿèÿàÿàÿðÿø ÿðÿèÿàÿàÿè ÿèÿðÿ øÿøÿðÿèÿèÿ èÿèÿðÿèÿàÿ ØÿØÿØÿØÿØÿ ØÿàÿèÿØÿÀÿ °ÿ¸ÿÀÿÀÿÐÿ àÿèÿðÿøÿøÿ øÿ øÿøÿðÿè ÿèÿðÿèÿèÿè ÿðÿðÿðÿøÿ øÿøÿðÿèÿ ðÿðÿ øÿðÿðÿèÿÐÿÈÿÈÿÀÿÈÿØÿàÿèÿ øÿøÿ (80(( ðÿàÿèÿèÿèÿè ÿèÿèÿðÿøÿ øÿøÿðÿ ðÿðÿèÿÐÿÐÿàÿèÿèÿøÿøÿðÿø ÿøÿøÿ ø ÿ øÿøÿðÿèÿðÿøÿøÿèÿàÿØ ÿØÿàÿèÿøÿ øÿøÿøÿ øÿøÿ (088(øÿøÿ øÿðÿðÿðÿàÿØÿøÿøÿèÿèÿèÿàÿ ØÿØÿàÿèÿèÿ øÿøÿðÿè ÿèÿØÿàÿðÿø ÿðÿøÿøÿèÿ P8àÿ`0 @0èÿ8øÿ ðÿøÿðÿèÿØÿ ØÿÈÿÀÿ¸ÿ¸ÿ ¸ÿ¸ÿ¸ÿÈÿÐÿ Øÿàÿèÿèÿàÿ Øÿàÿàÿàÿðÿ øÿðÿøÿ (øÿèÿøÿøÿðÿðÿðÿð ÿøÿøÿðÿèÿð ÿðÿèÿèÿðÿð ÿøÿ ( 0(øÿðÿðÿøÿøÿðÿ
The file is a .bin file.
RIFF¤WAVEfmt @€>data€ðÿèÿàÿàÿðÿø
The file is a .bin file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Let me try this one more time: Where does this file come from?
ASKER
Ray, attached is a jpeg image of how the file looks in the DB. This voice file is a .wav file and when i click on the recording link I can play the file.
A
vm.JPG
A
vm.JPG
What happens if your PHP script simply uses echo to write the file to the browser? No other browser output at all - just the echo. If that doesn't work, you might copy the file into the file system and send a link to the file into the browser output stream using something like this:
<bgsound src="path/to/wav/file.wav" />
Most browsers will play a bgsound tag. An alternative is recommended here:
http://www.w3.org/wiki/HTML/Elements/bgsound
<bgsound src="path/to/wav/file.wav"
Most browsers will play a bgsound tag. An alternative is recommended here:
http://www.w3.org/wiki/HTML/Elements/bgsound
ASKER
I noticed something interesting. I copied this voicemail table and dumped it on a windows machine to see if I can play the file when I click on the link, and I could. So it looks to me as if the file is located in my database and not in the "var/spool/asterisk/voicem ail/myMail s/203/INBO X" location. Any thoughts? Thank you.
ASKER
What I was able to do was to run the following query and dump the file in the /var directory;
select recording from voicemessages where uniqueid='1' into DUMPFILE 'tmp/voicemail_recording.w av';
and I was able to retrieve the file from the /tmp directory. Now the question I have is what happens if I have more than one file that I dump? When I tested this even though the query result showed me two rows were dumped I see only one file since all the files have same name (ie) voicemail_recording.wav. What can I do in this situation? Thank you.
select recording from voicemessages where uniqueid='1' into DUMPFILE 'tmp/voicemail_recording.w
and I was able to retrieve the file from the /tmp directory. Now the question I have is what happens if I have more than one file that I dump? When I tested this even though the query result showed me two rows were dumped I see only one file since all the files have same name (ie) voicemail_recording.wav. What can I do in this situation? Thank you.
Why dont you try what i have suggested.
ASKER
Will do.
Your bloa data is nothing but a wav file in raw binary data format you can write to a file.
First create a temp file using fopen
Write blob data into this file using fwrite. Fwrite(tenpfilehandle,row[ blobfield] )
Once temp file is written you can play as mentioned earlier .
First create a temp file using fopen
Write blob data into this file using fwrite. Fwrite(tenpfilehandle,row[
Once temp file is written you can play as mentioned earlier .
And dont forget as you are dealing with binary files you have to add b to file modes. rb to open and wb to write
ASKER
rinfo, my code is as follows:
while($row = mysql_fetch_assoc($result) )
{
echo '<tr bordercolor=/"#660066/">';
echo '<td>'. $row['origtime'].'</td>';
echo '<td>' . $row['callerid'].'</td>';
echo '<td>'. $row['duration'].'</td>';
$data=$row['recording'];
$wavFileName = "/tmp/voicemail_recording. wav";
$fh = fopen($wavFileName, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
echo '<td>';
echo '<audio controls="controls"> <source src="wavFileName" type="audio/wav">';
echo '</audio>';
echo '</td>';
echo '<td>'. $test.'</td>';
echo '</tr>';
}
I have attached a jpg of what I see on the screen. I am not able to play the file. On my Chrome browser I am able to see the image of the audio control box, but on my FF and IE browser the controls do not show up. What will I need to change? Thank you for your help.
A
voice.jpg
while($row = mysql_fetch_assoc($result)
{
echo '<tr bordercolor=/"#660066/">';
echo '<td>'. $row['origtime'].'</td>';
echo '<td>' . $row['callerid'].'</td>';
echo '<td>'. $row['duration'].'</td>';
$data=$row['recording'];
$wavFileName = "/tmp/voicemail_recording.
$fh = fopen($wavFileName, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
echo '<td>';
echo '<audio controls="controls"> <source src="wavFileName" type="audio/wav">';
echo '</audio>';
echo '</td>';
echo '<td>'. $test.'</td>';
echo '</tr>';
}
I have attached a jpg of what I see on the screen. I am not able to play the file. On my Chrome browser I am able to see the image of the audio control box, but on my FF and IE browser the controls do not show up. What will I need to change? Thank you for your help.
A
voice.jpg
Wavefilenane in src woukd be name of file you have created with the path
ASKER
you mean it is has to be "/tmp/voicemail_recording. wav" ?
Yes
ASKER
Changed the code to the following and I still have the same issue:
while($row = mysql_fetch_assoc($result) )
{
echo '<tr bordercolor=/"#660066/">';
echo '<td>'. $row['origtime'].'</td>';
echo '<td>' . $row['callerid'].'</td>';
echo '<td>'. $row['duration'].'</td>';
$data=$row['recording'];
$wavFileName = "/tmp/voicemail_recording. wav";
$fh = fopen($wavFileName, 'wb') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
echo '<td>';
echo '<audio controls="controls"> <source src="/tmp/voicemail_record ing.wav" type="audio/wav">';
echo '</audio>';
echo '</td>';
echo '<td>'. $test.'</td>';
echo '</tr>';
}
while($row = mysql_fetch_assoc($result)
{
echo '<tr bordercolor=/"#660066/">';
echo '<td>'. $row['origtime'].'</td>';
echo '<td>' . $row['callerid'].'</td>';
echo '<td>'. $row['duration'].'</td>';
$data=$row['recording'];
$wavFileName = "/tmp/voicemail_recording.
$fh = fopen($wavFileName, 'wb') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
echo '<td>';
echo '<audio controls="controls"> <source src="/tmp/voicemail_record
echo '</audio>';
echo '</td>';
echo '<td>'. $test.'</td>';
echo '</tr>';
}
ASKER
ok, looks like I have made some good progress, I am able to view the voice control box on my webpage and and am able to listen to the messages. The only problem is, even though there are several rows of messages in the db only the last message is being played, all other records picked up are unique to the row. My code is as follows;
/************************* ********** *********
$query = mysql_query("SELECT recording FROM voicemessages");
while ($row = mysql_fetch_assoc($query)) {
$data=$row['recording'];
$wavFileName = "voicemail_recording.wav";
$fh = fopen($wavFileName, 'wb') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
echo '<audio controls="controls">';
echo '<source src="voicemail_recording.w av" type="audio/wav">';
echo 'Your browser does not support this audio format.';
echo '</audio>';
echo "<br>";
echo "<br>";
}
************************** ********** ********/
Thanks for the help...
voice.jpg
/*************************
$query = mysql_query("SELECT recording FROM voicemessages");
while ($row = mysql_fetch_assoc($query))
$data=$row['recording'];
$wavFileName = "voicemail_recording.wav";
$fh = fopen($wavFileName, 'wb') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
echo '<audio controls="controls">';
echo '<source src="voicemail_recording.w
echo 'Your browser does not support this audio format.';
echo '</audio>';
echo "<br>";
echo "<br>";
}
**************************
Thanks for the help...
voice.jpg
Thats because you are assigning same wav filename to all records .make filename unique for all record.like recording_$id_file.wav.
ASKER
Rinfo, thank you very much. It was a interesting module to work on, thanks for all the help.
A
A