Uploading file into the server is very easy task. In this tutorial you will learn how you can upload folder with files and files of sub folder using PHP. The steps and the source code of this tutorial is given in the following link.

How to upload folderĀ using HTML and PHP

How to upload folder using PHP code

Comments (6)

  1. I tried to write it as closely as possible to the video but it might not have worked
    If it doesn't work, im sorry i tried my best…

    <!doctype html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>Untitled Document</title>

    </head>

    <body>

    <form action="#" method="post" enctype="multipart/form-data">

    Name Folder: <input type="text" name="foldername" /><br/></br/>

    Upload Folder: <input type="file" name="files[]" id="files" multiple directory="" webkitdirectory="" mozdirectory=""><br/><br/>

    <input class="button" type="submit" value="Upload" name='upload' />

    </form>

    </body>

    </html>

    <?php

    if(isset($_POST['upload']))

    {

    if($_POST['foldername']!="")

    {

    $foldername = $_POST['foldername'];

    if(!is_dir($foldername))

    mkdir($foldername);

    foreach ($_FILES['files']['name'] as $i -> $name)

    {

    if(strlen($_FILES['files']['name'][$i]) > 1)

    {

    move_uploaded_file($_FILES['files']['tmp_name'][$i], $foldername.'/'.$name;

    }

    }

    echo"Upload Successful";

    }

    else

    echo "Upload Failed (You Didn't Add a Folder Name)";

    }

    ?>

Comments are closed.