The file_get_contents function is mostly used to collect content on remote servers, but before using the file_get_contents function, we must turn on allow_url_fopen in php.ini.
Problem Description
fopen(), file_get_contents(), getimagesize(), etc. cannot obtain the content on the network normally. The specific performance is that if the parameter is a URL, it will return a null value
If it is windows, you can find it
allow_url_fopen is on
If it is possible in linux
Recompile PHP and remove the –with-curlwrapper parameter - remember to execute make clean before compiling.
We use allow_url_fopen when windows account is not opened
The code is as follows |
Copy code |
代码如下 |
复制代码 |
< ?php
$file_contents = file_get_contents(''http://www.bkjia.com/'');
echo $file_contents;
?>
|
< ?php
$file_contents = file_get_contents(''http://www.bkjia.com/'');
echo $file_contents;
代码如下 |
复制代码 |
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;
}
|
?>
|
cannot get the value, but we can use function_exists to determine whether this function is available.
The code is as follows |
Copy code |
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;
}
|
http://www.bkjia.com/PHPjc/445629.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445629.htmlTechArticleThe file_get_contents function is mostly used to collect content on the remote server, but before using the file_get_contents function, we have to use the file_get_contents function in php.ini Allow_url_fopen must be turned on. Problem description...