使用curl从url获取图像错误


Error get image from url using curl?

我有一个示例代码:

admin
-index.php
uploads
function saveImageFromUrl($my_img, $fullpath){
   if($fullpath!="" && $fullpath){
      $fullpath = $fullpath."/".basename($my_img);
   }
   $ch = curl_init ($my_img);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
   //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   $rawdata=curl_exec($ch);
   curl_close ($ch);
   if(file_exists($fullpath)){
      unlink($fullpath);
   }
   $fp = fopen($fullpath,'x');
   fwrite($fp, $rawdata);
   fclose($fp);
}
$dir = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR;
$fullpath = "uploads";
saveImageFromUrl('image.png', $dir.$fullpath);

和结果错误得到图像失败=>如何修复它?

//$dir = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR;
$fullpath = "../uploads";
saveImageFromUrl('image.png', $fullpath);