This topic is locked

Convert image from blob to file

3/3/2010 3:30:16 PM
PHPRunner General questions
F
frocco author

Hello,
I used phprunner to upload images to a blob in mysql.

I want to save the blob to a file and save the path in mysql.
In other words, I want to get rid of the blob storage for speed increase and image resize.
The images were uploaded and stored using your shoppingcart template.
Thanks
Frank

Sergey Kornilov admin 3/4/2010

You need to write a script that goes through your database table, retrieves BLOBs and save them to file system.
Here is the sample code.



while ($row = mysql_fetch_array(mysql_query('SELECT image, filename FROM tablename')))

{

$fp = fopen($row['filename'], 'wb');

fwrite($fp, $row['image']);

fclose($fp);

}
F
frocco author 3/4/2010



You need to write a script that goes through your database table, retrieves BLOBs and save them to file system.
Here is the sample code.



while ($row = mysql_fetch_array(mysql_query('SELECT image, filename FROM tablename')))

{

$fp = fopen($row['filename'], 'wb');

fwrite($fp, $row['image']);

fclose($fp);

}



Thank you