php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39051 move_uploaded_file fails with spaces and apostrophes
Submitted: 2006-10-05 17:41 UTC Modified: 2006-10-05 21:18 UTC
From: steele at agora-net dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 4.4.4 OS: Debian Sarge
Private report: No CVE-ID: None
 [2006-10-05 17:41 UTC] steele at agora-net dot com
Description:
------------
The move_uploaded_file() function fails when given a path that contains spaces or apostrophes.  Have tried manually escaping them as well, with the same result.  The copy() function does not fail in this respect.  Tested on three separate machines, and had members in the IRC channel test as well.

Reproduce code:
---------------
$target_path = "/path/to/share/ftp/foo blah/bc.png";
if(move_uploaded_file($_FILES[$fileName]['tmp_name'],$target_path)){
   echo basename( $_FILES[$fileName]['name']) . " has been successfully uploaded.\n";
    }
else{
   echo "Upload error!";
}

Expected result:
----------------
bc.png has been successfully uploaded.

Actual result:
--------------
Warning: move_uploaded_file(/path/to/share/ftp/foo blah/bc.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /path/to/includes/doUpload.php on line 54

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpu6A5ia' to '/path/to/share/ftp/foo blah/bc.png' in /path/to/includes/doUpload.php on line 54

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-05 17:42 UTC] steele at agora-net dot com
Forgot to paste the "Upload error!" at the end.
 [2006-10-05 17:49 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2006-10-05 18:53 UTC] tony2001@php.net
Cannot reproduce.
Of course "/path/to/share/ftp/foo blah/" directory must exist, otherwise it wouldn't work for obvious reasons.
 [2006-10-05 21:02 UTC] steele at agora-net dot com
I'm well aware of why it wouldn't work if the directory did not exist.  It does, and has been chmod'ed to 777.  Here is the reproduce code you requested:

<?php
$target_path = "/path/to/share/ftp/foo blah/bc.png";
$tmp = "/tmp/phpu6A5ia";
if(move_uploaded_file($tmp,$target_path)){
   echo "$tmp . " has been successfully uploaded.\n";
    }
else{
   echo "Upload error!";
}
?>
 [2006-10-05 21:13 UTC] tony2001@php.net
It doesn't work with ANY path because it's not an uploaded file.
No bug here.
 [2006-10-05 21:18 UTC] steele at agora-net dot com
Tony,

There is most certainly a bug.  The original case used an uploaded file.  I tried to make a shorter test case (which was my last post), however the script is longer than 20 lines.  On Freenode's IRC channel, others were able to duplicate this bug.  I have hacked the functions myself to work around this issue.  Apparently it's fixed in 5.1.2...I'll just wait for that to enter the Debian stable tree, I suppose.  I don't mean to sound contrite, but this was duplicated on several machines, and by several users on the IRC channels...there IS a bug here.  If you want to give me a day so I can get some free time, I'll write a script similar to the one in production for you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 02:01:28 2024 UTC