Path to the the folder above document root
Moderator: General Moderators
Path to the the folder above document root
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.)
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
Code: Select all
$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..';Re: Path to the the folder above document root
Thanks for all of your help Celauran!
Re: Path to the the folder above document root
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:
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/..\'
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_SEPARATORWarning: 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
Try just using "/" instead of the DIRECTORY_SEPARATOR constant, then.
Re: Path to the the folder above document root
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
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
Can someone let me know what they think might be going wrong here?
Re: Path to the the folder above document root
Check that the file name is included in the destination path.
Re: Path to the the folder above document root
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!