0

我正在尝试使用 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%3Bmaximize%3Dtrue%26amp%3Bimg%3Dupload%2Fcut1366795446185.jpg%26amp%3Bfiletype%3Dimage.jpg

可能是什么问题?十分感谢。

4

2 回答 2

1

$url = $_GET['url];

您是否在从中获取 url 的表单中使用任何 html 类型的东西。用户是否也在输入带有 html 标签的 url,或者您在 url 中包含了一些 html 标签。因为,如果 strcmp 没有给出 0 作为输出,这意味着两个 url 字符串不相等。一定有什么东西导致了这个问题。它可以是html标签。只需检查一次。

于 2013-07-01T13:06:25.923 回答
0

好的,问题是在 url 中有一些 & 我用 & 替换了这些。

$src=str_replace("&amp;", "&", $src);
于 2013-07-01T13:33:24.630 回答