|
問題描述
fopen(),file_get_contents(),getimagesize() 等都不能正常獲得網(wǎng)絡(luò)上的內(nèi)容,具體表現(xiàn)為凡參數(shù)是URL的,一律返回空值
如果是windows可找開
allow_url_fopen開啟
如果是否linux中可以
重新編譯PHP,去掉–with-curlwrapper 參數(shù)——編譯前記得先執(zhí)行 make clean。
windows 在未開戶allow_url_fopen時我們利用
| 代碼如下 |
復(fù)制代碼 |
|
< ?php
$file_contents = file_get_contents(''http://www./'');
echo $file_contents;
?>
|
是獲取不到值的,但我們可以利用function_exists來判斷此函數(shù)是否可用。
| 代碼如下 |
復(fù)制代碼 |
|
function file_get_content($url) {
if (function_exists(‘file_get_contents')) {
$file_contents = @file_get_contents($url);
}
if ($file_contents == ”) {
$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
|
|