0

this is code of my form page

<form action="gallerycontroller.php" method="post" enctype="multipart/form-data">   
<div>
<label class="desc" id="title4" for="Field4">
  Message
</label>                    
<div>
<textarea id="reply" name="name" spellcheck="true" rows="10" cols="50" tabindex="4"></textarea>                 
                             <!-- Custom icons with callback -->
                            <input type="file" name="file">

                            </div>
                          </div>

                          <div>

                          <div>
                                <div>
                                <input id="saveForm" name="saveForm" type="submit" value="Save">
                            </div>
                            </div>

and this is gallerycontroller page

<?php
include("model.php");
$db = new database;
$name = $_POST['name'];
$file = $_FILES['file'];
$filename = $file['name'];
$filetmp = $file['tmp_name'];
$file_ext = explode('.',$filename);
$file_ext = strtolower(end($file_ext));
$file_name_new = uniqid('',true) .'.'. $file_ext;
$file_destination = 'file/' .$file_name_new;
move_uploaded_file($filetmp, $file_destination);


        $designation=$_POST['principal'];
        $r=$db->insert($name,$file_destination);
        if($r>0)
    {   
            header("Location:upload.php?reply='sucess'");
    }
    else
    {
         header("Location:upload.php?reply='fail'");    
    }
 ?>

but i want to upload multiple files at a time this code of single file upload is working fine . Please convert this code into multi file upload if possible else refer new code.

Yogesh Arya
  • 134
  • 2
  • 14

1 Answers1

0

use "multiple" attribute for the file

<input type="file" name="img[]" multiple>

then use for loop in the php

$loop = 0;
foreach($_FILES['file']['name'] as $file){
    $filename = $file['name'][$loop];
    $filetmp = $file['tmp_name'][$loop];
    $file_ext = explode('.',$filename);
    $file_ext = strtolower(end($file_ext));
    $file_name_new = uniqid('',true) .'.'. $file_ext;
    $file_destination = 'file/' .$file_name_new;
    move_uploaded_file($filetmp, $file_destination);
    $loop++;
}
Demonyowh
  • 1,673
  • 1
  • 9
  • 14