一些内容的file_get_contents连接超时 [英] file_get_contents Connection Timed Out for some contents
问题描述
我正在开发一个用户可以在其中上传图片的网站.
i'm developing a site in which user can upload pictures.
一旦用户插入图像的url(仅远程),我就会将ajax调用到php并接受url并将其存储到服务器.
Once users insert the url ( only remote ) of image, i call a ajax to a php that take url and store it to the server.
问题出在file_get_contents:
The problem is the file_get_contents:
对于某些图像,它为我提供了连接超时,对于其他编号,则为我
For some images it gives me Connection Timed Out, for other no.
一些给我带来错误的图像是:
Some images that gives me that error are:
- http://www.lloydsbaiahotel.it/images/bgtop/03.jpg
- http://www.lloydsbaiahotel.it/images/bgtop/04.jpg
我简单地尝试以这种方式获取内容:
I simple try to fetch content in this way:
$img = "http://www.lloydsbaiahotel.it/images/bgtop/03.jpg";
$inbuf = file_get_contents($img);
var_dump($inbuf);
可能是什么问题?我必须更改服务器的某些配置吗?
What could be the problem? Do i have to change some configurations of my server?
推荐答案
尝试使用cURL,它提供了比file_get_contents更多的选项和控件,如下所示:
try to use cURL , it gives you more options and control than file_get_contents as the following :
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
$fp = fopen($save_to,'x');
fwrite($fp, $raw);
fclose($fp);
这篇关于一些内容的file_get_contents连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!