1

I'm developing an app that should upload with a for a directory to the server, I've alredy change the configuration for the max upload size in the php.iniindeed the upload is done correctly. I know the function move_uploaded_file to "store" a single file uploaded but my question is there is a way to use it for a directory uploaded?

This is my code:

HTML:

<form action="upload.php" 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>

PHP:

if (isset($_POST["submit"])) {
    if ($_FILES["file"]["error"] > 0) {
    } else {
        $storagename = $_FILES["file"]["name"];
        move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $storagename);
    }
}
$a= scandir("upload");
print_r($a);

With this code the result of the print is this:

Array ( [0] => . [1] => .. )

How can solve it?

Thank's

Edoardo
  • 599
  • 2
  • 9
  • 26
  • you want to upload directory or multiple files?? – Mudassar Saiyed Feb 16 '17 at 08:55
  • you want something like copying whole directory from one place to another place something like this http://stackoverflow.com/questions/2050859/copy-entire-contents-of-a-directory-to-another-using-php ? – Mittul At TechnoBrave Feb 16 '17 at 08:58
  • and please atleast print_r $_FILES and check how does it look, give some efforts mate – Rahul Feb 16 '17 at 09:03
  • If I'm not mistaken a directory upload will simply gather and upload all files in the directory so you're going to have mutliple file entries in you array. http://stackoverflow.com/questions/2233816/how-to-handle-multiple-file-upload-using-php would work in this case – apokryfos Feb 16 '17 at 09:06

1 Answers1

0

You have to iterate the $_FILES["file"]["name"].

I think this post can help you: How to upload folder with PHP?

Community
  • 1
  • 1
pwunderlich
  • 74
  • 1
  • 2
  • 8