Using move_uploaded_file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Using move_uploaded_file

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Using move_uploaded_file

Post 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?
Post Reply