Jump to content

Reading text from a php file


Orionsbelter

Recommended Posts

 

$tracking_file_location    =  "../dispatch-manager/logs/tracking_file.txt";
$tracking_file                 =  fopen("$tracking_file_location", "r") or die("Unable to open file!");
$tracking_file_size        =  filesize("$tracking_file_location");
$tracking_file_text        =  fread($tracking_file,$tracking_file_size);
fclose($tracking_file);
Link to comment
https://forums.phpfreaks.com/topic/291882-reading-text-from-a-php-file/
Share on other sites

Apologise, for some reason my text hasn't posted. 

 

 

$tracking_file_location    =  "../dispatch-manager/logs/tracking_file.txt";
$tracking_file                 =  fopen($tracking_file_location, "r") or die("Unable to open file!");
$tracking_file_size        =  filesize($tracking_file_location);
$tracking_file_text        =  fread($tracking_file,$tracking_file_size);
fclose($tracking_file);
 

How would we know why the file is in another directory? We are not sat beside you. 

 

It would be helpful if could actually explain what it is you are trying to do. Just posting a few lines of code is not going to yield you any helpful replies. Also if you are getting any error messages post them in full.

Yes - tell us what "is not working".  How smart do you think we are?  Smart enough to see something where there is nothing?

 

PS - add the code in my signature to turn on error checking at least.  Then run it and tell us what you get.

Specify the exact path to the file:

 

$tracking_file_location    =  "/home/www/exact/path/to/dispatch-manager/logs/tracking_file.txt";

 

Relative file paths will always cause problems. Especially, if the current file is included in a file that is located in a different location.

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.