我想使用php.This遠程服務器獲取XML數據是我的代碼來獲取XML,但我得到了布爾(假)從遠程服務器獲取XML數據在PHP
<?php
header ("content-type: text/plain");
$filename = file_get_contents("http://gep4.com/radio/wp-content/plugins/haze_radio/readme.txt");
var_dump($filename);
?>
我想使用php.This遠程服務器獲取XML數據是我的代碼來獲取XML,但我得到了布爾(假)從遠程服務器獲取XML數據在PHP
<?php
header ("content-type: text/plain");
$filename = file_get_contents("http://gep4.com/radio/wp-content/plugins/haze_radio/readme.txt");
var_dump($filename);
?>
這意味着出現了錯誤獲取文件的內容。你確定文件是否存在,或者你有權限讀取文件或其他內容?
返回值
該函數返回失敗讀取數據或FALSE
大概allow_url_fopen在php.ini中禁用
可以啓用它,如果你有訪問ot php.ini
或者,嘗試CURL代替
樣品捲曲呼叫
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "example.com");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
嘗試使用此方法獲取數據,它正在
function getPage($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');
$result['EXE'] = curl_exec($ch);
$result['INF'] = curl_getinfo($ch);
$result['ERR'] = curl_error($ch);
curl_close($ch);
unset($url, $referer, $agent, $header, $timeout);
return $result;
}
$url = "http://gep4.com/radio/wp-content/plugins/haze_radio/readme.txt";
var_dump(getPage($url));
真正捲曲。也許遠程服務器需要標頭信息... – Eugen