PHP file_get_contents returning false

前端 未结 4 1821
南笙
南笙 2021-01-04 00:12

Maybe I\'ve been sat here too long staring at this but WHY would file_get_contents return false here? I\'ve cut and paste the URL and it works fine

相关标签:
4条回答
  • 2021-01-04 00:18

    Probably allow_url_fopen in your php.ini: http://php.net/manual/en/filesystem.configuration.php

    Needs to be allowed.

    0 讨论(0)
  • 2021-01-04 00:26

    You may need to enable allow_url_fopen in your php.ini

    http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

    From the documentation:

    This option enables the URL-aware fopen wrappers that enable accessing URL object like files.

    Your server may be preventing you from opening a file located at a URL using file_get_contents.

    0 讨论(0)
  • 2021-01-04 00:36

    Try this:

    $query = http_build_query(array('search'=>$as_any, 'location'=>$location));
    $url = "http://jobs.github.com/positions.json?" . $query;
    

    The problem is that you weren't URL-encoding the search term, which contains a space. The request was returning a 400 error from the server, which you'd have noticed if you had error reporting enabled.

    0 讨论(0)
  • 2021-01-04 00:42

    Sometimes if file_get_contents return false (not found) you should see if the url is encoded.

    example:

    http://test.net/демо/

    Should be:

    https://test.net/%D0%B4%D0%B5%D0%BC%D0%BE/

    0 讨论(0)
提交回复
热议问题