Page 1 of 1

Using move_uploaded_file

Posted: Tue Mar 06, 2007 7:03 am
by mjseaden
Hi,

One of the problems with PHP is knowing when functions require an absolute path and when they don't.

move_uploaded_file appears to want an absolute path.

I'm doing:

Code: Select all

move_uploaded_file( $_FILES['file']['tmp_name'], $destpath );
I want to turn $destpath from a path relative to my web root in URL form (/htdocs/...) to an absolute path (e.g. C:\Apache\Apache2\htdocs\...), because this is the form move_uploaded_file seems to want. realpath() doesn't seem to be the right choice as it still seems to deal with paths relative to web root.

The ASP equivalent to what I want to do would be server.mappath (which realpath() is not, despite claims in the PHP manual).

Any ideas?

Many thanks

Re: Using move_uploaded_file

Posted: Tue Mar 06, 2007 7:34 am
by volka
file(), opendir(), move_uploaded_file() and all the other filesystem functions handle relative and/or absolute paths the same way. Relative paths are always relative to the current working directory which is not related to the webserver's root directory.
mjseaden wrote:I'm doing:

Code: Select all

move_uploaded_file( $_FILES['file']['tmp_name'], $destpath );
And now please do

Code: Select all

<?php
error_reporting(E_ALL); ini_set('display_errors', true);
echo 'docroot: ', $_SERVER['DOCUMENT_ROOT'], "<br />\n";
echo 'file: ', __FILE__, "<br />\n";
echo 'cwd: ', getcwd(), "<br />\n";
echo 'destpath: ', $destpath, "<br />\n";

move_uploaded_file( $_FILES['file']['tmp_name'], $destpath );
and post the output.

mjseaden wrote:The ASP equivalent to what I want to do would be server.mappath (which realpath() is not, despite claims in the PHP manual).
Examples?