Jump to content

Reading files.


Joshua4550

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.