Page 1 of 1

Path to the the folder above document root

Posted: Sun Nov 27, 2011 8:45 pm
by Markto
I am developing locally on windows in C:\web\www. My document root, as given by $_SERVER['DOCUMENT_ROOT'], is C:/web/www/ .

Many security tutorials for uploading files state that one should upload outside of their root directory, where apache cannot access it. So I guess this means C:/web/. However, I do not know how to specify that path. It would be even better if I could specify that path relative to the root. I want a variable that gives me the intended path to c:/web/ equivalent (so whatever is above the root, no matter what server I am on), and no matter where my file is. Can someone help me out here? ($path = c:/web/ is too static.)

Re: Path to the the folder above document root

Posted: Sun Nov 27, 2011 9:13 pm
by Celauran

Code: Select all

$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..';

Re: Path to the the folder above document root

Posted: Sun Nov 27, 2011 9:50 pm
by Markto
Thanks for all of your help Celauran!

Re: Path to the the folder above document root

Posted: Sun Nov 27, 2011 10:04 pm
by Markto
Hrm, I tried it, and it gave me this when echoed:

C:/web/www/\..
I tried to move a temp file there and got this error:
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\web\tmp\php1D00.tmp' to 'C:/web/www/\..'

I also tried:

Code: Select all

$_SERVER['DOCUMENT_ROOT'] . '..' . DIRECTORY_SEPARATOR
But got the same error, except the directory_separator appears in a more natural position:
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\web\tmp\php316B.tmp' to 'C:/web/www/..\'

Re: Path to the the folder above document root

Posted: Mon Nov 28, 2011 5:52 am
by Celauran
Try just using "/" instead of the DIRECTORY_SEPARATOR constant, then.

Re: Path to the the folder above document root

Posted: Mon Nov 28, 2011 8:11 pm
by McInfo
Both of these will give the directory above the document root.

Code: Select all

dirname($_SERVER['DOCUMENT_ROOT'])
realpath($_SERVER['DOCUMENT_ROOT'].'/..')

Re: Path to the the folder above document root

Posted: Wed Nov 30, 2011 9:45 pm
by Markto
That worked, thanks. However, I am still unable to move files to the directory. I am given an error that I am unable to move a file to that location (c:\web), although at least the location is right. Any ideas on why that might be? I am running on wamp, so my c:\web directory is my wamp directory. Could this be causing it?

Re: Path to the the folder above document root

Posted: Fri Dec 02, 2011 3:53 am
by Markto
Can someone let me know what they think might be going wrong here?

Re: Path to the the folder above document root

Posted: Fri Dec 02, 2011 12:22 pm
by McInfo
Check that the file name is included in the destination path.

Re: Path to the the folder above document root

Posted: Sat Dec 03, 2011 8:52 am
by Markto
You got it, thanks. I overlooked that, and thought it might have been some unseen file permissions error. You've really helped me out here - been setting this problem aside for a while now!