PHP file_get_contents return NULL Invalid solution

Source: Internet
Author: User

Problem description

fopen (), file_get_contents (), getimagesize () and so on are not normal access to the content of the network, the specific performance of any parameter is a URL, all return null value

If Windows can be found

Allow_url_fopen Open

If Linux can

Recompile php, remove the –with-curlwrapper parameter--before compiling remember to perform make clean first.


When Windows was not opening the allow_url_fopen, we used

The code is as follows Copy Code

< PHP
$file _contents = file_get_contents (' http://www.111cn.net/');
echo $file _contents;
?>

is not getting 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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.