1

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.

4
  • What content you are trying to read? Is there a error message? Paste some example. Commented May 17, 2010 at 10:20
  • It would be very helpful if you post your code, otherwise we can only guess what the problem might be. Maybe yahoo's webservers all died... Commented May 17, 2010 at 10:20
  • ... and it would also be helpful to see some error messages. Commented May 17, 2010 at 10:24
  • Check if allow_url_fopen is on. Commented May 17, 2010 at 10:25

1 Answer 1

7

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.