Re: move_uploaded_file
| From: | Roberto Aloi | Date: | Sat, 12 Dec 2009 11:49:30 +0000 |
| Subject: | Re: move_uploaded_file | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300424@lists.php.net to get a copy of this message | ||
This is exactly what I mean.
Documentation should never leave room to interpretation.
At least, this is what I think.
Roberto Aloi
On 11 Dec 2009, at 22:36, Ashley Sheridan <ash@ashleysheridan.co.uk> wrote:
On Fri, 2009-12-11 at 22:14 +0000, Roberto wrote:Hi Joseph, I'm perfectly fine with the concepts of absolute/relative path and webroot, trust me. For me it was just unclear from the documentation the fact that the "target path" in the move_uploaded_file function was "absolute" with respect to the file system and not to the "webroot". At the beginning I thought the function itself was taking care about adding the server root on its own to that path. Thinking carefully, it makes perfectly sense for the function to behave the way it actually does, since otherwise it would be impossible to get these files out of the server root in file system terms. Just, this should be written in CAPITAL LETTERS in the documentation. Thanks for the interest, Roberto Aloi http://aloiroberto.wordpress.com Twitter: @prof3taWhen used in PHP, an absolute path does not go off the web root.In Premise3 below, an absolute path of "/upload" will NOT bring up thedirectory"/home/prof3ta/projects/moodle/htdocs/upload" but rather simply "/upload"In Windows terms, an absolute path would be "C:\upload" versus "C:\home\prof3ta\projects\moodle\htdocs\upload". The only timean absolutepath is figured relative to the web root is when it is referencedin abrowser. At this point, for all intents and purposes, it locatesthe filebased on the web root. This is a fundamental difference betweenabsoluteand relative paths. Absolute: begins at "/" in Linux operating systems and "C:\" inWindows OSRelative: begins wherever the running script is located in thefile system.Joseph Roberto wrote:feedback_tool"HI, Premise 1: echo exec("pwd"); -> "/home/prof3ta/projects/moodle/htdocs/use anPremise 2: I have an "upload" folder with 777 permissions under: /home/prof3ta/projects/moodle/htdocs/upload Premise 3: The server root is obviously htdocs: /home/prof3ta/projects/moodle/htdocs This said, the following doesn't work: <?php $uploads_dir = "/upload"; $tmp_name = $_FILES["file"]["tmp_name"]; $name = $_FILES["file"]["name"]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); ?> The following does work: <?php $uploads_dir = "../upload"; $tmp_name = $_FILES["file"]["tmp_name"]; $name = $_FILES["file"]["name"]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); ?> I consider it as a documentation bug (in the sample code theyabsolute path). I indeed believe I *should* be able to use both of them if not documented otherwise. I will dig into the C implementation of the move_uploaded_file function and I'll check, though. Cheers, Roberto Aloi http://aloiroberto.wordpress.com Twitter: @prof3taI've never had any issue with the documentation for this function. I think it might just be an issue with interpretation? :p Thanks, Ash http://www.ashleysheridan.co.uk