7

I want to get and play the WAV file stored in MySql Db using PHP and Zend-Framework. But I am not able to do so. I want to do this in 2 steps: 1. Convert the BLOB as .wav file 2. Play that .wav file in a new window.

Please help me............

Thanks in advance......

Charles
  • 50,943
  • 13
  • 104
  • 142
Pushpendra
  • 4,344
  • 5
  • 36
  • 64
  • 4
    save your self the hassle, don't store it in the db in the first place, in general this is never a good idea (same goes for images and other binary files) –  Feb 06 '11 at 01:03

2 Answers2

4

To store the data in the database, you would do something like this:

$tmpName  = $_FILES['userfile']['tmp_name'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

And then you would insert $content into the blob field in the sql query. To read the files, it would be something like:

$query = "SELECT name, type, size, content " .
     "FROM upload WHERE id = '$id'";

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;

To read the file, just have the 2nd code executed and the file should download. You can point your flash player or what ever you use to the url with the above code, and it should work.

Hope this helped REF: http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx

Colum
  • 3,844
  • 1
  • 22
  • 26
-1
$query = "select voiceBlob from voiceTable where pk = ".$_GET['id'];
$result = mysql_query($query);
$row=mysql_fetch_assoc($result)  ;
$data = $row["voiceBlob"];

$ourFileName = "uploads/voiceFile.wav";
$fh = fopen($ourFileName, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);

This is to take data from DB and store in a file. Now play the voiceFile.wav

  • 1
    -1, this is an SQL-injection hole. See: http://www.tizag.com/mysqlTutorial/ and read on till the section that describes SQL-injection, also see: http://stackoverflow.com/questions/332365/xkcd-sql-injection-please-explain – Johan Aug 29 '11 at 12:24