Jump to content

Uploading to selected Folder


evilgenius82

Recommended Posts

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!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.