-1

我有一个示例代码:

admin
-index.php
uploads

在 index.php 我使用代码:

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);

结果错误获取图像失败=>如何解决?

4

1 回答 1

0
//$dir = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR;
$fullpath = "../uploads";
saveImageFromUrl('image.png', $fullpath);
于 2013-05-27T04:36:22.120 回答