How to Upload Multiple Files in PHP

In this article, you will learn how to upload multiple files in PHP. Upload Multiple Files In order to upload multiple files, you can use…

The post How to Upload Multiple Files in PHP appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to upload multiple files in PHP.

Upload Multiple Files

In order to upload multiple files, you can use the move_uploaded_file() method.

<html>
<body>
	<form method='post' action='' enctype='multipart/form-data'>
		
		<!-- Input of type multiple files -->
 		<input type="file" name="file[]" id="file" multiple>
		
		<!-- Upload button -->
 		<input type='submit' name='submit' value='Upload'>
	</form>

	<?php 

		// Path to store uploaded file
		$path = "C:/xampp/htdocs/";

		// If the submit button is pressed
		if(isset($_POST['submit'])){
 
 			// Count total files
 			$fileCount = count($_FILES['file']['name']);

 			// Iterate through the files
 			for($i = 0; $i < $fileCount; $i++){

  				$file = $_FILES['file']['name'][$i];
 
  				// Upload file to $path
  				move_uploaded_file($_FILES['file']['tmp_name'][$i], $file);
 
 			}
		} 
?>
</body>
</html>

Note: The move_uploaded_file() method functions by moving an uploaded file into a new location.

The post How to Upload Multiple Files in PHP appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-03-06T04:49:57+00:00) How to Upload Multiple Files in PHP. Retrieved from https://www.scien.cx/2021/03/06/how-to-upload-multiple-files-in-php/

MLA
" » How to Upload Multiple Files in PHP." Ariessa Norramli | Sciencx - Saturday March 6, 2021, https://www.scien.cx/2021/03/06/how-to-upload-multiple-files-in-php/
HARVARD
Ariessa Norramli | Sciencx Saturday March 6, 2021 » How to Upload Multiple Files in PHP., viewed ,<https://www.scien.cx/2021/03/06/how-to-upload-multiple-files-in-php/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Upload Multiple Files in PHP. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/06/how-to-upload-multiple-files-in-php/
CHICAGO
" » How to Upload Multiple Files in PHP." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/03/06/how-to-upload-multiple-files-in-php/
IEEE
" » How to Upload Multiple Files in PHP." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/03/06/how-to-upload-multiple-files-in-php/. [Accessed: ]
rf:citation
» How to Upload Multiple Files in PHP | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/03/06/how-to-upload-multiple-files-in-php/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.