Multiple file upload in php

0 votes
I wish to upload several files, put them in a folder, and store the path in the database. Any useful examples of uploading numerous files.

Note: Any form of file is acceptable.
Jul 30, 2022 in PHP by Kithuzzz
• 38,000 points
813 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

I am aware that this is an old article, but anyone attempting to upload numerous files might find some more explanation helpful. What you must do is as follows:

  • Input name must be be defined as an array i.e. name="inputName[]".
  • Input element must have multiple="multiple" or just multiple.
  • In your PHP file use the syntax "$_FILES['inputName']['param'][index]".
  • Make sure to check the array for empty strings; these could be file names or path entries. Prior to counting, use an array filter().

Here is an example:

HTML:

<input name="upload[]" type="file" multiple="multiple" />

PHP:

//$files = array_filter($_FILES['upload']['name']); //something like that to be used before processing files.

// Count # of uploaded files in array
$total = count($_FILES['upload']['name']);

// Loop through each file
for( $i=0 ; $i < $total ; $i++ ) {

  //Get the temp file path
  $tmpFilePath = $_FILES['upload']['tmp_name'][$i];

  //Make sure we have a file path
  if ($tmpFilePath != ""){
    //Setup our new file path
    $newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];

    //Upload the file into the temp dir
    if(move_uploaded_file($tmpFilePath, $newFilePath)) {

      //Handle other code here

    }
  }
}

I hope this helps you.

answered Jul 31, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In PHP

0 votes
1 answer

How can I upload Multiple file in php?

Hello @kartik, Multiple files can be selected and ...READ MORE

answered Aug 27, 2020 in PHP by Niroj
• 82,840 points
903 views
0 votes
1 answer

How to check file extension in upload form in PHP?

Hello @kartik, Using if( $ext !== 'gif') might not ...READ MORE

answered Nov 8, 2020 in PHP by Niroj
• 82,840 points
17,496 views
0 votes
1 answer

How can you upload a file using PHP?

Hello, To upload a file by using PHP, ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,840 points
968 views
0 votes
1 answer

Error:PDOException SQLSTATE[HY000] [2020] No such file or directory in php?

Hello, I checked php -i | grep pdo and noticed ...READ MORE

answered Apr 2, 2020 in PHP by Niroj
• 82,840 points
1,626 views
0 votes
0 answers
0 votes
1 answer

How can I select and upload multiple files with HTML and PHP using HTTP POST?

Hello @kartik, This is possible in HTML5. Example (PHP ...READ MORE

answered Sep 15, 2020 in PHP by Niroj
• 82,840 points
2,132 views
0 votes
0 answers

Increase max_execution_time in PHP?

My server support post_max_size 192MB and max_execution_time 600 sec so when ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,040 points
691 views
0 votes
0 answers

Multiple Image Upload PHP form with one input

I want to have multiple image upload forms ...READ MORE

Jun 13, 2022 in PHP by narikkadan
• 63,600 points
712 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
1,837 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
11,629 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP