How to Upload Multiple Images in PHP
- 1). Choose a web page on your site where the users will see the form to upload multiple files or create a new page that only you will be able to use in the backend of the site.
- 2). Open the page in a text editor or web authoring tool, such as Notepad or Dreamweaver.
- 3). Type in the HTML for the form. The form will work as the user interface for uploading the files. The code should look something like this:
"<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<p>Upload Files:
<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="submit" value="Send" />
</p>
</form>"
This form will have three slots to choose the files that you want to upload. If you the ability to upload more than three files, type in the "<input type-file name=file[] />" line to add another upload field. Don't type in the quotation marks on the first and last lines of the code. - 4). Type in the PHP code that will handle the uploaded files. This code will place the files that are uploaded into the same directory as the form.
"<?php
foreach ($_FILES["files"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
echo"$error_codes[$error]";
move_uploaded_file(
$_FILES["files"]["tmp_name"][$key],
$_FILES["files"]["name"][$key]
) or die("Problems with upload");
}
}
?>
</body>
</html>"
Don't use the quotation marks on the first and last lines. Save the file and upload it to your server. - 5). Test the form by typing in the full web address for the form in your Internet browser. Select the files to upload from your computer, one file for each field, and then click the "Send" button.
Source...