Skip to main content

HTML5 Directory Upload Using PHP

HTML5 allows you to upload a complete directory by using directory attribute. This method is more user friendly than any other file uploading method. We can upload a complete directory at a time using this way. At this time, method is working only in Chrome and webkit browsers by using webkitdirectory attribute we can also add mozdirectory attribute for mozila browser support. Here is a simple example to upload directory using PHP.

Live Demo Download Script

HTML FORM

<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>

Take a look on the html markup, we need to add box brackets with name attribute. It will collect all files in an array.

PHP

We need to handle uploaded files with php multi upload hander method.

$count = 0;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    foreach ($_FILES['files']['name'] as $i => $name) {
        if (strlen($_FILES['files']['name'][$i]) > 1) {
            if (move_uploaded_file($_FILES['files']['tmp_name'][$i], 'upload/'.$name)) {
                $count++;
            }
        }
    }
}

Comments

  1. Not working on Internet Explorer!

    ReplyDelete
    Replies
    1. Not really surprising...

      Delete
    2. Works only on modern browsers supporting webkit. Chrome is one.

      Delete
  2. not working with firefox =(

    ReplyDelete
  3. Do not upload directory structure, only files in folder

    ReplyDelete
  4. code is working very perfectly under chrome but the problem is in mozila it not work

    ReplyDelete
  5. how to file upload multiple folder on server by selecting dropdown

    ReplyDelete
  6. I tried to add the attribute mozdirectory but it is not working for firefox

    ReplyDelete
  7. Can anyone please give a solution for functional working in all browsers

    ReplyDelete
  8. is it possible to add into a mysqli function?

    ReplyDelete
  9. not working in mozila . please given any suggestion

    ReplyDelete
  10. Hello Admin, thank you for enlightening us with your knowledge sharing. PHP has become an inevitable part of web development, and with proper PHP training in Chennai, one can have a strong career in the web development field.

    ReplyDelete
  11. Only 20 file upload how to increase??

    ReplyDelete
  12. When uploaded, the directory is not uploaded. Instead, files of that directory are uploaded. I am using Google Chrome.

    ReplyDelete
  13. Replies
    1. Find out new theme free installation https://goo.gl/01sPGc

      Delete
  14. When uploaded, the directory is not uploaded. Instead, files of that directory are uploaded.how it possible to upload directory also

    ReplyDelete
  15. Every morning, I usually have a habit of logging in to hotmail outlook login facebook and checking out hotmail emailboxes

    ReplyDelete
    Replies
    1. Find out new theme free installation https://goo.gl/01sPGc

      Delete
  16. Find out new theme free installation https://goo.gl/01sPGc

    ReplyDelete
  17. Thanks for sharing this script with us. It is very useful. To know more about PHP visit PHP Training institute in Chennai? | PHP Training | PHP Course in Chennai

    ReplyDelete
  18. Thank your site! information your share is useful to me!
    Accessing my site will have many interesting things for you.
    beauty face

    ReplyDelete
  19. Mais importante ainda, esses números de usuários também colocariam o Gmail na frente do hotmail.com entrar, executado pela Microsoft, tornando o Gmail o serviço de email mais usado no mundo. Em julho de 2011, a Microsoft disse que o hotmail.com entrar tinha 360 milhões de usuários. A empresa ainda não oferece uma atualização desde então.

    ReplyDelete
  20. This is really an interesting blog I love it and enjoyed it so much keep sharing like this.
    WINDOWS 10 PRODUCT KEY FULL VERSION

    ReplyDelete

Post a Comment

Popular posts from this blog

Multiple File Upload with PHP

Sometimes we need to allow our users to upload multiple file upload. On my previous post I was shown the basic of simple file upload with PHP. Today I am going to show you how to allow users to upload multiple files. It is almost similar like simple file upload but we need to do some modification with html markup and php code. multiple attribute is needed to add on the html markup. Major web browsers like Firefox, Chrome, Safari and IE 9+ support this attribute. Now I am going to show you how to upload multiple file with PHP and basic HTML form.

Live Comment System with jQuery Ajax PHP and MySQL

Recently I have been made a post that focused on how to submit form without page refreshing. That post shows the basic functionality of using jQuery Ajax. On the same follow this post will describe how we can create a comment system to post an instant comment without page refreshing. Let's start...

Resize Image While Uploading with PHP

On my previous post I was shown an example how to upload file with php and html. It was based on php simple image upload functionality. Today I am going to show you little bit advance of image uploading. Suppose if you run a website and want to allow users to upload image files than you need to think little bit about server's space and bandwidth. For this purpose you need to do some optimization with image files. Image resize while uploading is one of them. All major website do it in the same way. If a user uploads a 5mb image file they resize it in different sizes and store on there server. It helps them to seed up there website and reduce there budget. Now take a look, how we can do it ourself.