2013-07-01 117 views
0

我正尝试使用file_get_contents PHP函数下载图像。file_get_contents不适用于某些图像

它通过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%3Bmaximize%3Dtrue%26amp%3Bimg%3Dupload%2Fcut1366795446185.jpg%26amp%3Bfiletype%3Dimage.jpg

可能是什么问题? 非常感谢。

回答

1

$ url = $ _GET ['url];

您是否在使用任何html类型的东西来获取网址。是否在那里用户输入的网址与HTML标签太多,或者你是包括一些网址的HTML标签。因为,如果strcmp没有给出0作为输出,这意味着两个url字符串不相等。肯定有什么是造成这个问题的原因。它可以是html标签。只需检查一次。

+0

有了,我已经发布我发了仅仅用这个GET头值的URL(所以我认为它不是这样的,你提的问题): URL = HTTP%3A%2F%2Fwww.liberoquotidiano。它%2Fresizer.jsp%3Fw%3D500%26amp%3Bh%3D-1%26amp%3Bmaximize%3Dtrue%26amp%3Bimg%3Dupload%2Fcut1366795446185.jpg%26amp%3Bfiletype%3Dimage.jpg – michele

+0

我没有看到任何关于html在获取参数 – michele

0

Oks问题是,在url中有一些&我用&代替这些。

$src=str_replace("&amp;", "&", $src); 
相关问题