Jump to content

Recommended Posts

Hello,

 

I'm just following some php tutorials regarding file access and can't seem to successfully open a file. Here is what I have:

 

$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab');
if(!$fp){
echo '<p>There was a problem with your order, sorry!</p>';
exit;
}

 

 

I have an "orders" directory that resides just outside of "/Library/WebServer/Documents/", which is $DOCUMENT_ROOT, is this the correct path?

 

Thanks,

 

Jason

Link to comment
https://forums.phpfreaks.com/topic/136144-fopen-problems/
Share on other sites

../ does not mean document root. It means the folder immediately above the one you're in.  Example:

 

http://www.somesite.com/folderA/folderB/folderC/somescript.php

 

inside somescript.php:

 

../orders.txt is the same as

http://www.somesite.com/folderA/folderB/orders.txt

 

../../orders.txt is the same as

http://www.somesite.com/folderA/orders.txt

 

etc...

Link to comment
https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710132
Share on other sites

Well I was mostly just explaining to him what ../ meant so as to give him an idea of how to find the correct path.  If

 

/Library/WebServer/Documents/

 

is the document root, and you're saying that your orders directory is just 'outside' of that, do you mean to say that this

 

/Library/WebServer/orders/orders.txt

 

is the path to the fie?

 

Link to comment
https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710150
Share on other sites

I know that ../ gets me out of the dir. In this example script the full path based on the OSX install of Apache is "/Library/WebServer/Documents/" - where the script is being run from. So, does "/Library/WebServer/Documents/../orders/orders.txt" point to a file located between "/Library/WebServer/Documents/" and "orders/" i.e., a file sitting in "/Library/WebServer/Documents/"?

 

In any case it doesn't seem to matter where I'm trying to fopen() from, if I use "orders/orders.txt" or even "orders.txt" as the file path param, it always returns false.

Link to comment
https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710722
Share on other sites

If the full path of your file is for instance

 

/Library/WebServer/Documents/foo/bar/orders/orders.txt

 

and you do

 

/Library/WebServer/Documents/../orders/orders.txt

 

that's the same as saying

 

/Library/WebServer/Documents/bar/orders/orders.txt

 

which will result in a 404 error or false or whatever, depending on how you're trying to access it.

 

 

Link to comment
https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710765
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.