我收到一个我无法弄清楚的错误,我正在做的是我有一个字符串或一堆网址,我将它们放入一个数组然后循环数组并调整大小和上传图像,但我得到这个错误。非常感谢任何帮助!
错误
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, ',');
答案 0 :(得分: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
你看到图像还是错误?您可以尝试使用其他工具下载图像,例如{iix php cUrl上的wget
命令。请注意,代码没有错误 - 这是ia 服务器响应,HTTP代码为400 - 请求错误,因此您连接到图像服务器,但file_get_contents
生成的HTTP GET请求无效