0

I've a php code that extract some information from a .dat file uploaded by the user. Now i want to apply this treatment on a set of uploaded file. so the user can choose a set of file when he click upload the treatment has to be done on each file. i've tried this but it's not working :

     <form method="post" enctype="multipart/form-data">
      <label>Selectionner le fichier .dat</label>
      <input type="file" name="excel" />
      <br />
      <input type="submit" name="import" class="btn btn-info" value="Import" />
     </form>

thank you in advance.

  • 1
    yes it will naturally won't work, you'll need actual PHP codes, first process the form, usually its under `$_FILES`, since you're expecting multiple files add `[]` in the name attribute. this link can give you an idea https://thedebuggers.com/multiple-files-upload-using-html-php/ – Kevin Sep 12 '18 at 07:14
  • Possible duplicate of [How to get the file extension in PHP?](https://stackoverflow.com/questions/10368217/how-to-get-the-file-extension-in-php) – Ronnie Oosting Sep 12 '18 at 07:19
  • 1
    what do you need exactly? multiple uploads? – parpar Sep 12 '18 at 07:21
  • https://secure.php.net/manual/en/function.move-uploaded-file.php Example #1 Uploading multiple files – brombeer Sep 12 '18 at 07:23
  • what php code? You need to tell us the whole story. At the moment its very unclear what youre asking. – DevDonkey Sep 12 '18 at 07:37
  • the user upload a set of files : the PHP code extract some information from each file and store it in the database. this is the whole story nothing special. – Oussama Fathallah Sep 12 '18 at 07:58

1 Answers1

1

To let the user select multiple files you have to use the multiple attribute and add brackets [] to the name of the input.

You can do this:

<form method="post" enctype="multipart/form-data">
      <label>Selectionner le fichier .dat</label>
      <input type="file" name="excel[]" multiple />
      <br />
      <input type="submit" name="import" class="btn btn-info" value="Import" />
</form>

Then you can parse the $_FILES array and you will find all the uploaded files, for example:

Array
(
    [excel] => Array
        (
            [name] => Array
                (
                    [0] => img1.PNG
                    [1] => img2.PNG
                    [2] => img3.jpg
                    [3] => img4.png
                )

            [type] => Array
                (
                    [0] => image/png
                    [1] => image/png
                    [2] => image/jpeg
                    [3] => image/png
                )

            [tmp_name] => Array
                (
                    [0] => /tmp/phpWh5NRz
                    [1] => /tmp/php6KEOer
                    [2] => /tmp/phprLvUBi
                    [3] => /tmp/phplTP0Y9
                )

            [error] => Array
                (
                    [0] => 0
                    [1] => 0
                    [2] => 0
                    [3] => 0
                )

            [size] => Array
                (
                    [0] => 63515
                    [1] => 54484
                    [2] => 14001
                    [3] => 84938
                )

        )

)
Omagerio
  • 495
  • 2
  • 11