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

Post a Comment

Popular posts from this blog

Multiple File Upload with Progress Bar using PHP & jQuery

Some days age I have created a post that deals with How we can upload file with progress bar using php and jQuery. Some of my readers asked me how we can upload multiple files with progress bar. In this post I am going to show you how we can upload multiple files with progress bar.We can upload multiple files with progress bar exactly same way as I shown previous. But we need to do some modification with our file upload form and our php script to handle multiple files.

Force File Download with PHP

If you want to control or track your downloadable contents then a force file downloader script can give you more option. Especially if you want make images or other stemming contents like music file (mp3, wav, ogg), video files (flv, mp4, ogg, 3gpp), css, JavaScripts or even a php file downloadable then you must need to use a force file downloader script.
In this post I am going to share a simple but useful force file downloader script.

File Upload with Progress Bar using jQuery and PHP

In this post you will learn how to create a AJAX file uploading system with progress bar using jQuery and PHP. For this purpose we will going to use jQuery Form Plugin. It is a easy to use and powerful jQuery AJAX form submitting plugin. It supports XMLHttpRequest Level 2 and iframe file transportation. That's why it will work for both old and new browsers.