note 72064 deleted from features.file-upload by danbrown

From: Date: Sun, 23 Jan 2011 17:02:14 +0000
Subject: note 72064 deleted from features.file-upload by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176142@lists.php.net to get a copy of this message
Note Submitter: jkuckartz1984 at hotmail dot com ---- When uploading on a windows system and working with different partitions and different drive letters, uploading might not work correctly with the shown example. The workaround is include the current operating directory in the target dir, as follows: <?php //you can delete the 'echo' commands and the '$temploc='-line $currentdir=getcwd(); $target_path = $currentdir . "/2nddir/" . basename($_FILES['uploadedfile']['name']); echo "Target: $target_path<br>"; $temploc=$_FILES['uploadedfile']['tmp_name']; echo "Temploc: $temploc<br>"; if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br><br>"; } else { echo "There was an error uploading the file, please try again!<br><br>"; } ?> If the $currentdir is omitted and not used in $target_path: Target: /2nddir/file.ext Temploc: /ms4w/tmp/\php12C.tmp Warning: move_uploaded_file(/ms4w/tmp/\php12C.tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\Public\www\dir\test.php Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/ms4w/tmp/\php12C.tmp' to '/2nddir/file.ext' in D:\Public\www\dir\test.php There was an error uploading the file, please try again! If it's written as the code shown above, it works perfectly: Target: D:\Public\www\dir/2nddir/file.ext Temploc: /ms4w/tmp/\php12C.tmp The file file.ext has been uploaded My initial thought the "\" in front of the temporary file was causing the problem. But don't bother about the "\", it does no harm!

« previous php.notes (#176142) next »