【发布时间】:2018-02-09 17:37:56
【问题描述】:
我正在开发一个包含大量文件的网站。因此,我为我的文件(例如图像和 txt 文件)制作了一个单独的服务器。问题是 php 的 file_get_contents 函数不适用于该服务器。
我尝试了echo file_get_contents("http://url");,但我什么也没得到,但是当我尝试echo file_get_contents("http://google.com"); 时,我得到了谷歌的主页。 curl 连接也是如此。
$ch = curl_init();
$url = "http://running-files.rf.gd/hello.html";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$body = curl_exec($ch);
$info = curl_getinfo($ch);
$error = curl_errno($ch);
curl_close($ch);
echo $body;
我的猜测是 .htaccess 文件中需要一些东西。有人有什么建议吗?
【问题讨论】:
-
那么使用curl也无法得到响应?使用 curl_getinfo 从连接中提取所有信息,例如状态代码。
-
@Pete 你介意我要求你指定网址吗?
-
running-files.rf.gd 但它重定向到主服务器
-
file_get_contents() 默认情况下应该遵循重定向,但 curl 不会。您需要指定
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); -
我需要获取running-files.rf.gd/Trails/…等文件
标签: php .htaccess curl file-get-contents