时间:2021-07-01 10:21:17 帮助过:38人阅读
- <code><!--?php
- $url = $_GET['img'];
- $filename = basename($url);
- $img = grabImage($url,$filename);
- echo '<img src="https://img.gxlcms.com/https://img.gxlcms.com/'.$img.'"-->';
- 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>
然后访问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="https://img.gxlcms.com/https://img.gxlcms.com/'.$img.'"-->';
- 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>
然后访问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;