0

i want to download the image from one server, and want to save the binery data into mysql blob field. but its not working.

  1. if i am displaying the $picture1 then it shows the un-readable characters. byt $picture2 is not displaying.

  2. if i try to save it in the table, then its not saving in the table.

how can i save this into my blob field.

$picture1 = GetImageFromUrl($url);
$picture2 = addslashes(fread(fopen($picture, "r"), filesize($picture)));

print_r($picture1)
print_r($picture2)

function GetImageFromUrl($link)
{

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_POST, 0); 
curl_setopt($ch,CURLOPT_URL,$link); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result=curl_exec($ch); 
curl_close($ch); 
return $result;
}
j0k
  • 22,600
  • 28
  • 79
  • 90
asif hameed
  • 163
  • 1
  • 3
  • 13

1 Answers1

1

Try encoding it with base64 before saving in your database field:

echo base64_encode($picture1);

And to read out from database, you need to decode it:

echo base64_decode($picture);

But be sure to send the right headers with it, for example:

header('Content-Type: image/png');

But please read this before: Storing Images in DB - Yea or Nay? and consider if you really want to save it in your database.

I am strictly against it, but it's in your power

Community
  • 1
  • 1
dan-lee
  • 14,365
  • 5
  • 52
  • 77