tags:

views:

73

answers:

4

On a server I have the file some.php. I try to read the contents 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.

A: 

Check your filesystem permissions. The file might cannot be opened for reading. Also make sure the path to the file is correct.

andreas
+4  A: 

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);
ThiefMaster
+1  A: 

Check if allow_url_fopen is on.

powtac
allow_url_fopen On Onthis is my phpinfo
Bharanikumar
+1  A: 

Try to display your PHP configuration with phpinfo() and see if something is blocking you to access the file.

And first try to access your local file, rather than one hosted?

Check:

allow_url_fopen

display_errors

Have you tried on the local file?

Starx
How to check any thing blocking or not
Bharanikumar
Your code is working when i test it, its your configuration or firewall, check it
Starx
i thing...the reason might be...server hsting...
Bharanikumar