Page 1 of 1

Why is so friggin hard to open files in php?

Posted: Mon Jan 27, 2014 5:18 am
by boylesg
I have this code:

$FileName = DIRECTORY_SEPARATOR."public_html".DIRECTORY_SEPARATOR."BushlandRecovery".DIRECTORY_SEPARATOR."JobsList.txt";

$JobsListFile = fopen($FileName,"r");
if ($JobsListFile)
{

No matter what I do with the file name or the directory structure I cannot open the f'ing file. Not in r mode or w mode.

I cannot detect any files with file_exits(...)

There are no specific settings in CPanel that lets me give php read permission etc.

So how do you open a bloody file in php?????

I fail to understand why it needs to be so difficult.

Re: Why is so friggin hard to open files in php?

Posted: Mon Jan 27, 2014 6:21 am
by Celauran
It isn't terribly difficult. I'm guessing you're running into problems because you're starting with a slash, denoting an absolute path, and /public_html is not a top level directory on any machine I've encountered. $_SERVER['DOCUMENT_ROOT'] will resolve the path to your, well, document root and you can build from there.

Code: Select all

$file_name = $_SERVER['DOCUMENT_ROOT'] . '/BushlandRecovery/JobList.txt';
$fh = fopen($file_name, 'r');
etc.[/syntax]