PHP expert |
|
<html>
<head>
<script type="text/javascript">
function addFile()
{
document.getElementById("files").innerHTML += '<br /><input type="file" name="files[]" />';
}
</script>
</head>
<body>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
foreach($_POST['files'] as $key => $value) {
// $key is de huidige index van de array.
// $value is de waarde van de array.
// aanroepen: $value['tmp_name'], $value['type'], enz..
}
} else {
?>
<form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" enctype="multipart/form-data">
<div id="files">
<input type="file" name="files[]" />
</div>
<input type="button" value="Add file" onclick="addFile()" /><br />
<input type="submit" value="Submit!" />
</form>
<?php
}
?>
</body>
</html>
<html> <head> <script type="text/javascript"> function addFile() { document.getElementById("files").innerHTML += '<br /><input type="file" name="files[]" />'; } </script> </head> <body> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { foreach($_POST['files'] as $key => $value) { // $key is de huidige index van de array. // $value is de waarde van de array. // aanroepen: $value['tmp_name'], $value['type'], enz.. } } else { ?> <form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" enctype="multipart/form-data"> <div id="files"> <input type="file" name="files[]" /> </div> <input type="button" value="Add file" onclick="addFile()" /><br /> <input type="submit" value="Submit!" /> </form> <?php } ?> </body> </html>
Dit zou moeten werken |