I have a database where images are saved as blob. Now, I want to convert this blob data into image files.
So I have made this code, but its not giving any result
$sql_icon = "SELECT $off_table.icon,$off_table.id
FROM $off_table,$cnt_table,$ctg_table
WHERE $off_table.id = $cnt_table.id
AND $off_table.id = $ctg_table.id
AND ".$cond_api."
AND ".$cond_nt."
AND ".$cond_cnt."
AND ".$cond_ctg;
$result_icon = mysql_query($sql_icon);
while($row = mysql_fetch_array($result_icon))
{
$image = $row["icon"];
$id = $row["id"];
$file = fopen("./image/".$id.".jpg","w");
fwrite($file, base64_decode($image));
fclose($file);
}
The issue is, I am getting files but no extensions and if I rename them to ".jpg" extension, then its displaying "no preview available"
NOTE:
The images are saved into database by this method
$sql = "INSERT INTO aw_offers_v2
(
id,name,description,payout_type,
payout,expiration_date,creation_date,preview_url,
tracking_url,categories,countries,countries_short,
api_key,network_id, icon,icon_size)
VALUES
('$id','$name','$description','$payout_type',
'$payout','$expiration_time','$creation_time','$preview_url',
'$tracking_url','$categories','$countries','$countries_short',
'$api','$api_url','".mysql_real_escape_string(file_get_contents($cover_image_src))."','".strlen(file_get_contents($cover_image_src))."')";
If I write this code
echo '<img src="data:image/jpeg;base64,'. base64_encode($image).'" />';
then I can see the images properly. That means the images are successfully saved.
But I can't store them in folder as files.