Skip to content

Instantly share code, notes, and snippets.

@PUSRISTEK
Created November 18, 2016 06:36
Show Gist options
  • Save PUSRISTEK/359f3c8a9f43e6ef90aad6e332c117e8 to your computer and use it in GitHub Desktop.
Save PUSRISTEK/359f3c8a9f43e6ef90aad6e332c117e8 to your computer and use it in GitHub Desktop.
How to Upload Multi Files
<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form>
<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
// basename() may prevent filesystem traversal attacks;
// further validation/sanitation of the filename may be appropriate
$name = basename($_FILES["pictures"]["name"][$key]);
move_uploaded_file($tmp_name, "data/$name");
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment