输入banner图图片脚本导航/分类

php下载图片出现链接被重置

我的代码是这样的:

';
function grabImage($url,$filename){
if ($url == "") return false;
ob_start(); 
readfile($url); 
$img = ob_get_contents(); 
ob_end_clean();
$fp = @fopen($filename,"a"); 
fwrite($fp,$img);
fclose($fp); 
return $filename;
}
?>

然后访问http://test.com/?img=https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/12950259_974006612694869_608041607_n.jpg出现链接被重置,该怎么改?使用表单传递url可以正常下载。

回复内容:

我的代码是这样的:

';
function grabImage($url,$filename){
if ($url == "") return false;
ob_start(); 
readfile($url); 
$img = ob_get_contents(); 
ob_end_clean();
$fp = @fopen($filename,"a"); 
fwrite($fp,$img);
fclose($fp); 
return $filename;
}
?>

然后访问http://test.com/?img=https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/12950259_974006612694869_608041607_n.jpg出现链接被重置,该怎么改?使用表单传递url可以正常下载。

因为表单传入的参数值会进行urlencode。
因为你直接url来访问,img的参数值中有'/',没有urlencode;