0

($data 编码为 jpg 图像,然后通过以下代码对其进行解码并尝试将其存储在图像文件夹中)

 $data = base64_decode($data);         //decoded image
 $im = imagecreatefromstring($data); 
 if ($im !== false) 
 {
   header('Content-Type: image/jpg');
   imagejpeg($im);
   imagedestroy($im);
 }
 else
 {
   echo 'An error occurred.';
 }
 // storing it in image folder on 
 $success = file_put_contents('images/5.jpg',$im);
 echo $success ? $im : 'Unable to save the file.';  
4

2 回答 2

2

The $im variable does not contain the image data, it's an opaque resource that can be used with the gd functions but nothing else. Writing it to a file won't do what you want.

To save an image as JPEG you should use the imagejpeg function and provide file path as second parameter. Alternatively, if the original image data was already in JPEG format, you can write the $data string to the file (in which case, why do you bother decoding it into an image?).

于 2013-09-21T08:10:12.073 回答
0

can you please used this

chdir('images');

// and then 

$success = file_put_contents('5.jpg',$im);

can you please change your present working directory

check this chdir

于 2013-09-21T08:08:02.107 回答