Page 1 of 1

Right path using fopen

Posted: Sat Oct 19, 2013 7:31 am
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

Re: Right path using fopen

Posted: Sat Oct 19, 2013 6:18 pm
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")

Re: Right path using fopen

Posted: Mon Oct 21, 2013 4:56 am
by priyankagound
Try out with the below code:

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

Hope this helps.

Re: Right path using fopen

Posted: Sat Dec 14, 2013 12:13 pm
by Booster
Thanks all for your help.