Qadir Hussain Qadir Hussain - 5 months ago 32x
SQL Question

How to extract a BLOB image and save it in the directory Using PHP

I have saved images in my Database as BLOB, now i want to extract the images and save these into a directory.

Till now I m able to view the BLOB image using following code.

$con = mysql_connect("genetech002" , "username" , "mypass");
$db = mysql_select_db("Mydatabase", $con);
$sql = "SELECT * FROM hs_hr_emp_picture WHERE emp_number = 5";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);


I can see the image in my browser after executing the above script. but now i want to save this image in a directory (on my server).
Please help.



You can save it with file_put_contents().

file_put_contents("pic.jpg", $row['epic_picture']);