Jump to content

Recommended Posts

I'm gonna cut it short, because this is really starting to ... me off.

 

The following code will not work.

$file = "alltime.txt";
$handle = fopen($file, 'r');

 

The reason for this not working?

Warning: fopen(alltime.txt) [function.fopen]: failed to open stream: No such file or directory in /home/*myuser*/public_html/*mysite*.com/Sources/Statistics.inc on line 4

The file is in the same directory as the file running the code.

The files permissions are set for the owner to read, write, and execute.

 

Why is it saying it does not exist?

Link to comment
https://forums.phpfreaks.com/topic/182411-reading-files/
Share on other sites

The code is in a file Statistics.inc. It is likely that this has been included/required into another file that is in a different folder. The fopen() is relative to the main file, not the included/required file. Is this the case?

 

You either need to form a correct relative path, an absolute file system path (using $_SERVER['DOCUMENT_ROOT'] concatenated with the path/file information would make this easy), or alter the current working directory (CWD) to be that of where the alltime.txt file is located.

Link to comment
https://forums.phpfreaks.com/topic/182411-reading-files/#findComment-962567
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.