我有一个示例代码:
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);
结果错误导致图片失败=>如何解决?
答案 0 :(得分:0)
//$dir = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR;
$fullpath = "../uploads";
saveImageFromUrl('image.png', $fullpath);