|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41989 move_uploaded_file & relative path
Submitted: 2007-07-13 09:46 UTC Modified: 2007-07-19 15:50 UTC
From: gerome dot fournier at infomaniak dot ch Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.2.3 OS: Debian sarge
Private report: No CVE-ID: None
 [2007-07-13 09:46 UTC] gerome dot fournier at infomaniak dot ch
The function move_uploaded_file does not work if the destination
path is a relative path. The function returns TRUE, but the file is
not moved at all.

If I replace the following line:

  $dest_file = "./tmp/test.txt";


  $dest_file = getcwd() . "/tmp/test.txt";

then everything works as expected. In the reproduce code, I provide
the HTML form used to upload a file, and the PHP code to process the
uploaded file. PHPINFO of the server running this script is available here:

Reproduce code:
<form enctype="multipart/form-data" METHOD="POST" action="upload.php">
    <input type="file" name="import_file"/>
    <input type="submit" name="submit"/>

    if (is_uploaded_file($_FILES["import_file"]["tmp_name"])) {
        $dest_file = "./tmp/test.txt";
        if (move_uploaded_file($_FILES["import_file"]["tmp_name"], $dest_file)) {
            // check the uploaded file has really been moved or not
            if (! file_exists($dest_file))
                echo "ERROR: uploaded file not moved as $dest_file";
                echo "OK: uploaded file moved as $dest_file";

Expected result:
OK: uploaded file moved as ./tmp/test.txt

Actual result:
ERROR: uploaded file not moved as ./tmp/test.txt


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-13 09:57 UTC]
Please try with prefork MPM.
 [2007-07-13 10:07 UTC]
But please try this patch first.
 [2007-07-19 15:50 UTC]
Assuming the patch is ok. 
Fixed in CVS.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 12:01:25 2019 UTC