Right path using fopen

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
Booster
Forum Newbie
Posts: 8
Joined: Tue Oct 08, 2013 12:28 pm

Right path using fopen

Post by Booster »

Hi all,

With $DOCUMENT_ROOT being C:/wamp/www/ , and the script I run being in the folder C:/wamp/www/php/src/02/ ,I would like to create a file at the path $DOCUMENT_ROOT/php/src/02/orders/orders.txt by using the code :

Code: Select all

$fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); 
However, it seems that it not the right path.

I equally tried the following code in vain :

Code: Select all

$fp = fopen("$DOCUMENT_ROOT/../..orders/orders.txt", 'ab'); 
Thanks in advance for your help,

Booster
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Right path using fopen

Post by requinix »

To put it more simply, you want to create orders/orders.txt in the script's directory.

Code: Select all

fopen(__DIR__ . "orders/orders.txt", "ab")
priyankagound
Forum Commoner
Posts: 27
Joined: Thu Sep 19, 2013 2:53 am

Re: Right path using fopen

Post by priyankagound »

Try out with the below code:

$handle = fopen($_SERVER['DOCUMENT_ROOT'] . '/orders/orders.txt', 'ab');

Hope this helps.
Booster
Forum Newbie
Posts: 8
Joined: Tue Oct 08, 2013 12:28 pm

Re: Right path using fopen

Post by Booster »

Thanks all for your help.
Post Reply