Loading file from root directory

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
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Loading file from root directory

Post by djwk »

Hi

I have tried this:

Code: Select all

$file = "./count.dat";
$fh = fopen($file, 'r');
$count1 = fgets($fh);
fclose($fh);
However the './' does not load the file from the root directory. Basically I have a folder inside the root directory, the php file with the above code in is in that folder, i want to read from a file in the root directory.

Can anyone help?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remove the leading dot.
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

If you mean like this '/count.dat' I already tried that
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That's the way to reference root, so unless you define root differently than, likely, the rest of us, your script may not have the permission to read there.
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

I tried it again and recieved the same error:

Warning: fopen(/count.dat): failed to open stream


I need this to work, how annoying!
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

OHHH! Sorry my idiotic mistake.

I forgot its an addon domain, so its located in another sub folder. I'll try adding the folders to the filename and let you know what happens :)
Post Reply