Skip to content

Instantly share code, notes, and snippets.

@shashank-p
Created August 28, 2019 08:36
Show Gist options
  • Save shashank-p/d09faacafc1fa017c0cacac18fce0483 to your computer and use it in GitHub Desktop.
Save shashank-p/d09faacafc1fa017c0cacac18fce0483 to your computer and use it in GitHub Desktop.
PHP Multiple Image Upload
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="my_file[]" multiple>
<input type="submit" value="Upload">
</form>
<?php
if (isset($_FILES['my_file'])) {
$myFile = $_FILES['my_file'];
$fileCount = count($myFile["name"]);
$dest = "upl/";
for ($i = 0; $i < $fileCount; $i++) {
?>
<p>File #<?= $i+1 ?>:</p>
<p>
Name: <?= $myFile["name"][$i] ?><br>
Temporary file: <?= $myFile["tmp_name"][$i] ?><br>
Type: <?= $myFile["type"][$i] ?><br>
Size: <?= $myFile["size"][$i] ?><br>
Error: <?= $myFile["error"][$i] ?><br>
</p>
<?php move_uploaded_file($myFile["tmp_name"][$i], $dest.$myFile["name"][$i]); ?>
<?php
}
}
?>
</body>
</html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment