-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 に答える