venkir Posted July 11, 2006 Share Posted July 11, 2006 Hi all Gurus:I have not been able to make file upload work for about 2 days now and am at the end of my wits-----------Code Snippet ----------------------<?php require ('page.inc'); // Check for error $userfile_error = $_FILES['userfile']['error']; if ( $userfile_error > 0) { $pagecontent = $pagecontent . 'Problem :'; switch ($userfile_error) { case 1: $pagecontent = $pagecontent . 'File exceeded upload_max_filesize'; break; case 2: $pagecontent = $pagecontent . 'File exceeded max_file_size'; break; case 3: $pagecontent = $pagecontent . 'File only partially uploaded'; break; case 4: $pagecontent = $pagecontent . 'No file uploaded'; break; } exit; } // Extract Form fields $userfile = $_FILES['userfile']['name']; // Check the input values if ( empty($userfile)) { echo 'One of the required fields was empty, please check and try again'; } else { // Put the file where we want it $upfile = '/uploads/' . $userfile; $tmpfile = 'c:\\wamp\\tmp\\' . basename($_FILES['userfile']['tmp_name']); echo $tmpfile . " <--- used basename and appended to the path <br>"; echo $_FILES['userfile']['tmp_name'] . "<--- Original tmp file<br>"; echo $_FILES['userfile']['name'] . " <--- FILES name var <br>"; echo $_FILES['userfile']['size'] . " <--- FILES size var<br>"; $pagecontent = $pagecontent . $_FILES['userfile']['type'] . " <--- FILES type var<br>"; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) { echo 'Error: Could not move file to destination directory.'; } else { echo "<h2>Processing File:" . $upfile. "</h2>\n<br>"; } } else { echo 'Error: Possible file upload attack :'. $_FILES; }?>-----------End Code Snippet ----------------------and the results in the browser arec:\wamp\tmp\php4B.tmp <--- used basename and appended to the path c:/wamp/uploads\php4B.tmp<--- Original tmp fileangus_input.csv <--- FILES name var 1906 <--- FILES size vartext/plain <--- FILES type varError: Could not move file to destination directory. with addtional warnings Warning: move_uploaded_file(/uploads/angus_input.csv) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\GeoCoding\geocodecsv.php on line 49Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/uploads\php4B.tmp' to '/uploads/angus_input.csv' in C:\wamp\www\GeoCoding\geocodecsv.php on line 49Clearly the problem is the tmp upload file full path name which is 'c:/wamp/uploads\php4B.tmp' (NOTICE the different slash direction)How do I fix this? I tried stripslashes, tried re-constructing the tmp file and then providing it to function move_uploaded_file, but it still does not move itCan anyone help? Thanks a lot in advance-Venki Quote Link to comment https://forums.phpfreaks.com/topic/14270-file-upload-problems-specifically-move_uploaded_file-function/ Share on other sites More sharing options...
venkir Posted July 11, 2006 Author Share Posted July 11, 2006 I fixed my own problem. I hardcoded the entire path instead of using the relative path for the destination filename and for some reason it worked. All documentaion says that it is relative to where the php script executes. Anyway that was my fix if it helps anybody.-Venki Quote Link to comment https://forums.phpfreaks.com/topic/14270-file-upload-problems-specifically-move_uploaded_file-function/#findComment-56074 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.