Home > Backend Development > PHP Tutorial > php下载图片出现链接被重置

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

WBOY
Release: 2016-06-06 20:10:15
Original
966 people have browsed it

我的代码是这样的:

<code><?php $url = $_GET['img'];  
$filename = basename($url);
$img = grabImage($url,$filename);
echo '<img  src="'.$img.'" alt="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;
}
?>
</code>
Copy after login
Copy after login

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

回复内容:

我的代码是这样的:

<code><?php $url = $_GET['img'];  
$filename = basename($url);
$img = grabImage($url,$filename);
echo '<img  src="'.$img.'" alt="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;
}
?>
</code>
Copy after login
Copy after login

然后访问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;

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template