1

这是我的代码

<?php
$url = "http://i.imgur.com/qV39tsL.gif";
$ch = curl_init();
echo $ch;
$timeout = 20;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$content = curl_exec($ch);
curl_close($ch);
echo $content;
?>

在我的环境中,我的上网速度有点慢,所以有时我无法从 imgur 下载一些 gif。

但让我感到困惑的是,我经常收到如下错误:

**ERROR 500: Internal Server Error.**

我在stackoverflow中查找,PHP中的Curl不应该让服务器停机。

那么有人会告诉我为什么我会收到 ERROR 500:Internal Server Error 吗?

谢谢~~~

4

2 回答 2

0

试试这个(经过测试),缺少一些指令。

不包括标题,只会显示.gif文件的二进制内容而不是图像本身。

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://i.imgur.com/qV39tsL.gif');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$content = curl_exec($ch);
curl_close($ch);
//Display the image in the browser
header('Content-type: image/gif');
echo $content;

/* You could also save the file to your server at the same time
using the following outside this comment
// save on server option
$fh = fopen('filename.gif', 'w');
fwrite($fh, $content);
fclose($fh);
*/

?>
于 2013-09-01T15:11:58.010 回答
0

我已经毫无问题地执行了脚本。它可能是你的服务器上安装 curl 的东西。

检查服务器错误日志以更好地查看错误描述。也许您需要重新安装 curl。

于 2013-09-01T14:56:15.257 回答