Multiple file upload in php

Sometimes we need to allow our users to upload multiple file upload. 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. Now I am going to show you how to upload multiple file with PHP and basic HTML form. You may also like Multiple file upload in Codeigniter and Multiple Image Upload in PHP.

PHP Code

for($i=0; $i<count($_FILES['file']['name']); $i++) {

    $tmpFilePath = $_FILES['file']['tmp_name'][$i];
    $shortname = $_FILES['file']['name'][$i];
    $filename = date('YmdHis').$_FILES['file']['name'][$i];
    $filePath = "./public/course_work/".$filename;
    $ext = pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION);

    $file = basename($shortname,".".$ext);


    if(move_uploaded_file($tmpFilePath, $filePath))
    {
        // Write code after move file
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *