Skip to content

Instantly share code, notes, and snippets.

@sdglhm
Created September 30, 2015 16:10
Show Gist options
  • Save sdglhm/c72c59b8a0bbc586e5bb to your computer and use it in GitHub Desktop.
Save sdglhm/c72c59b8a0bbc586e5bb to your computer and use it in GitHub Desktop.
<html>
<body>
<form method="post" enctype="multipart/form-data" id="upload_form">
<input type="button" value="Add" onclick="addUploader()">
<div id="upload_div">
<input type="file" accept="image/*" name="upload[]">
</div>
<input type="submit" value="Upload files">
</form>
<script>
function addUploader () {
var dv = document.getElementById("upload_div");
var newp= document.createElement("p");
dv.appendChild(newp);
newp.innerHTML='<input type="file" name="upload[]" accept="image/*" />';
}
</script>
<hr/>
<?php
for ($i=0; $i < count($_FILES['upload']['name']); $i++) {
$extention = pathinfo($_FILES['upload']['name'][$i],PATHINFO_EXTENSION);
move_uploaded_file($_FILES['upload']['tmp_name'][$i] , "a-file-" . microtime() . "-" . $i . "." . $extention );
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment