开发者

PHP file read not working

开发者 https://www.devze.com 2022-12-31 02:05 出处:网络
On a server I have the file some.php. I try to read the content开发者_Go百科s using file_get_content and fread. Both these don\'t read my content.

On a server I have the file some.php. I try to read the content开发者_Go百科s using file_get_content and fread. Both these don't read my content.

If I try some other URL like yahoo.com, these functions are reading the contents. Why does this happen?

$my_conetn =  file_get_contents("http://example.com");
echo $my_conetn;

The above snippet is not working.

$handle = fopen($filename, "r");
$contents = fread($handle, 20);
echo $contents;
fclose($handle);

Also the above snippet is not working.

How to check my server? Is there any file read operation locked or not?

edit: I am not sure, but it is only my server file that can't be read. I can read the other server links. So I contact my hosting provider, then I get back to you guys/gals.


When using file functions to access remote files (paths starting with http:// and similar protocols) it only works if the php.ini setting allow_url_fopen is enabled. Additionally, you have no influence on the request sent. Using CURL is suggested when dealing with remote files.

If it's a local file, ensure that you have access to the file - you can check that with is_readable($filename) - and that it's within your open_basedir restriction if one is set (usually to your document root in shared hosting environments).

Additionally, enable errors when debugging problems:

ini_set('display_errors', 'on');
error_reporting(E_ALL);
0

精彩评论

暂无评论...
验证码 换一张
取 消