【发布时间】:2014-09-23 12:13:26
【问题描述】:
我在我的网站上启用file_get_contents 时遇到问题。有人建议我可以改用 curl。
这是我原来的函数,使用file_get_contents:
function getFile($fileQuery){
global $user, $pass, $domain;
return file_get_contents("https://$user:$pass@$domain:2083/".$fileQuery);
}
这是我尝试过的,使用 curl:
function getFile($fileQuery){
global $user, $pass, $domain;
//return file_get_contents("https://$user:$pass@$domain:2083/".$fileQuery);
$url = "https://$user:$pass@$domain:2083/".$fileQuery;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 4000); //timeout in seconds
$result = curl_exec($ch);
echo "<pre>"; print_r($result);
curl_close($ch);
}
但是,它返回一个空白页。
有什么想法吗?
【问题讨论】: