Why is so friggin hard to open files in php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
boylesg
Forum Newbie
Posts: 7
Joined: Mon Jan 27, 2014 5:09 am

Why is so friggin hard to open files in php?

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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]
Post Reply