【问题标题】:file_get_contents don't work with some imagesfile_get_contents 不适用于某些图像
【发布时间】:2013-07-01 12:08:59
【问题描述】:

我正在尝试使用 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

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

【问题讨论】:

    标签: php image file-get-contents imagedownload


    【解决方案1】:

    $url = $_GET['url];

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

    【讨论】:

    • 使用我发布的 url,我发送了一个带有这个 GET 值的简单标题(所以我认为你提到的不是这样的问题):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
    • 我在 get 参数中没有看到任何关于 html 的内容
    【解决方案2】:

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

    $src=str_replace("&amp;", "&", $src);
    

    【讨论】:

      猜你喜欢
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多