evilgenius82 Posted July 14, 2012 Share Posted July 14, 2012 Hi I tried something new today & have got stuck on the last section. My plan was to have a form in which you select the file you want to upload and then select the folder in where you want to save your upload. I managed to get the folders visible in a drop down option. When I click upload, the file fails to move from temp to 'folder'. Below is the code FORM <div id="UserManagementBox"> <form method="POST" action="upload_file.php" enctype="multipart/form-data" > <table> <tr> <td>Please Select File:</td> <td><input type ="file" name="upfile" > </td> </tr> <tr> <td>Please Rename File:</td> <td><input name="name" type="text" id="name"> </td> </tr> <tr> <td>Please Select Folder:</td> <td><select name="selectionField"> <? Dir_Iterator = new DirectoryIterator("file_pool"); foreach ($Dir_Iterator as $dirname) { if (!$dirname->isDot()) { if ($dirname->isDir()) { $folderName = $dirname->getFilename(); $folderPath = $dirname->getPathname(); echo' <option value="'. $folderPath. '"">' . $folderName . '</option>'; } } } Form Process <? $target_path = $_POST['selectionField'] ; $target_path .$_FILES ['upfile']['name']; if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['upfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; print_r($_POST['selectionField'] ); } ?> Error Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\xampp\htdocs\upload_file.php on line 20 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpC415.tmp' to 'file_pool\New Installations' in C:\xampp\htdocs\upload_file.php on line 20 There was an error uploading the file, please try again!file_pool\New Installations Any form of help will by highly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/265664-uploading-to-selected-folder/ Share on other sites More sharing options...
lordshoa Posted July 14, 2012 Share Posted July 14, 2012 echo' <option value="'. $folderPath. '"">' . $folderName . '</option>'; echo" <option value='". $folderPath. "'>'" . $folderName . "'</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/265664-uploading-to-selected-folder/#findComment-1361522 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.