0

我遇到了一个我无法弄清楚的错误,我正在做的是我有一个字符串或一堆 url,我将它们放入一个数组中,然后循环数组并调整大小并上传图像,但我收到这个错误。任何帮助将不胜感激!

错误

file_get_contents(http://a513.phobos.apple.com/us/r1000/094/Purple/v4/d4/e4/02/d4e402a3-a485-4d4c-cf9b-90b0af391626/mzl.wbbwbbab.png ) 
[function.file-get-contents]: failed to open stream: HTTP request failed! 
HTTP/1.0 400 Bad Request in "My File" on line 53

PHP

include("picture-resize.php");

    $image = $_POST['thumbnail'];
    $slug = $_POST['slug'];
    $images = $_POST['screenshots'];
    $list = explode(",", $images);      
    $listlength = count($list);

    $i = 0;

    $image = $_POST['thumbnail'];

    $path = parse_url($image, PHP_URL_PATH);

    $filename = $slug.'-'.$i;

    $extension = pathinfo($path, PATHINFO_EXTENSION);

    $file = $filename.'.'.$extension;

    file_put_contents('../tmp/' . $file, file_get_contents($image));

    $picture = new pic_resize();

    $picture->load('../tmp/'.$file);

    $picture->resizeToWidth(125);

    $picture->save('../images/125x125/'.$file, $picture->image_type);

    unlink('../tmp/'.$file);

    $thumbnail = $file;

    $new_list = array();

    while($listlength > $i) {

        $path = parse_url($list[$i], PHP_URL_PATH);

        $extension = pathinfo($path, PATHINFO_EXTENSION);

        $file = $filename.'.'.$extension;

        file_put_contents('../tmp/' . $file, file_get_contents($list[$i]));

        $picture = new pic_resize();

        $picture->load('../tmp/'.$file);

        $picture->resizeToWidth(640);

        $picture->save('../images/640x320/'.$file, $picture->image_type);

        $picture->resizeToWidth(310);

        $picture->save('../images/310x205/'.$file, $picture->image_type);

        unlink('../tmp/'.$file);

        array_push($new_list, $file);

        $i++;
    }
    $screenshots = implode($new_list, ',');
4

1 回答 1

0
$a = file_get_contents("http://a513.phobos.apple.com/us/r1000/094/Purple/v4/d4/e4/02/d4e402a3-a485-4d4c-cf9b-90b0af391626/mzl.wbbwbbab.png");
echo strlen($a);

对我有用。它可能是您的环境中的错误(防火墙、wiruses、ISP 修改的 HTTP 请求等)。尝试将此链接粘贴到浏览器中:

http://a513.phobos.apple.com/us/r1000/094/Purple/v4/d4/e4/02/d4e402a3-a485-4d4c-cf9b-90b0af391626/mzl.wbbwbbab.png

您看到图像或错误吗?您可以尝试其他工具来下载图像,例如wgetunix ot php cUrl上的命令。请注意,这不是代码错误 - 此 ia服务器响应HTTP 代码 400 - 错误请求,因此您已连接到图像服务器,但生成的 HTTP GET 请求file_get_contents无效。

于 2013-04-20T06:30:21.337 回答