note 72064 added to features.file-upload

From: Date: Sun, 31 Dec 2006 18:01:07 +0000
Subject: note 72064 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-121148@lists.php.net to get a copy of this message
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! ---- Server IP: 194.109.193.94 Probable Submitter: 82.173.147.74 ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.php Edit -- https://master.php.net/note/edit/72064 Del: integrated -- https://master.php.net/note/delete/72064/integrated Del: useless -- https://master.php.net/note/delete/72064/useless Del: bad code -- https://master.php.net/note/delete/72064/bad+code Del: spam -- https://master.php.net/note/delete/72064/spam Del: non-english -- https://master.php.net/note/delete/72064/non-english Del: in docs -- https://master.php.net/note/delete/72064/in+docs Del: other reasons-- https://master.php.net/note/delete/72064 Reject -- https://master.php.net/note/reject/72064 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121148) next »