1

I have a folder which has bunch of files.

I use below code to upload multiple files:

<form method="post" enctype="multipart/form-data">
    <input type="file" name="files[]" id="files" multiple="" directory="" webkitdirectory="" mozdirectory="">
    <input class="button" type="submit" value="Upload" />
</form>

It works fine but it does not upload parent folder why? I also want to upload the folder which files belong.

ehah
  • 675
  • 1
  • 7
  • 11

1 Answers1

0

You can't "upload" parent folder, but there is another way you can do it.

You can have a user enter the name of the folder into a text box: <input type='text' name='folder_name' placeholder='Enter Folder Name..' required />

Then in your upload script use:

$dirName = $db->real_escape_string(stripslashes(trim($_POST['folder_name'])));
if(!is_dir($dirName)){
   mkdir($dirName);
}

foreach ($_FILES['files']['name'] as $f => $name) {
   if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $dirName.$name))
}
Colum
  • 996
  • 2
  • 8
  • 23