我正在尝试下载一个带有file_get_contents PHP函数的图像。
它通过GET接收一个urlencode(url)并返回内容。这是代码:
<?php
$url=($_GET["url"]);
$url2 = ("http://www.liberoquotidiano.it/resizer.jsp?w=500&h=-1&maximize=true&img=upload/cut1372677360319.jpg&filetype=image.jpg");
echo "<br>Url 1 is via GET <br> Url2 is a variable instantiated in the script and its value is manually inserted.";
echo "<br>file_get_contents Url2 work, but with url1 not,althought the url content is the same. ";
echo "<br>1.url= ".$url;
echo "<br>2.url= ".$url2;
$r=strcmp($url2,$url);
if($r==0){
echo "correct";
}else{
echo "<br><br>string compare with url and url2 return ".$r;
}
echo "<br><br>launch: file_get_contents(url) => ";
$image_data = file_get_contents($url);
echo $image_data;
?>
url和url2是相同的,但是php strcmp代码返回1,而不是0…我不明白为什么。如果我启动
file_get_contents($url);
它不起作用,我也没有返回任何价值。如果我启动
file_get_contents($url2);
它正常工作。
奇怪的是url和url2包含相同的值,但结果不同。
这是脚本中的链接:http://www.clouderize.it/michele/get_cont.php?url=http%3A%2F%2Fwww.liberoquotidiano.it%2Fresizer.jsp%3Fw%3D500%26amp%3Bh%3D-1%26amp%3最大化%3True%26amp%3img%3Upload%2Fcut1366795446185.jpg%26amp%3文件类型%3Dimage.jpg
可能是什么问题?非常感谢。
$url=$_GET['url];
你在获取url的表单中使用了任何html类型的东西吗。是用户也在输入带有html标签的url,还是您在包含一些带有url的html标签。因为,如果strcmp没有给出0作为输出,则意味着两个url字符串不相等。一定有什么原因导致了这个问题。它可以是html标签。只需检查一次。
Oks问题是在url中有一些&我已将这些替换为&。
$src=str_replace("&", "&", $src);