10May/0712
Create Multiple File Upload Form Using Javascript And Php
Currently I'm working on a project that required an upload form to be dynamic. That is when I want more file to upload I don't need to upload lets say 5 at a time, because I can add more field to it. The idea is simple, I just need to manipulate DOM to add the field and modify PHP manual a little bit to match my need. Look below the full source.
<?php
if(isset($_POST['submit'])){
//$files = array_values($_FILES["data"]);
//print_r($_FILES["data"] );die();
$count = sizeof($_FILES['data']['name']);
for($i = 0; $i < $count; $i++){
if ($_FILES['data']['error'][$i] != UPLOAD_ERR_OK) {
//show error message or silently go to next file.
echo 'File upload error ' . $_FILES['data']['error'][$i] . '.<br />';
}else{
//do what you want to do here...
//eg : save file, scan it, etc.
echo 'file ' . $_FILES['data']['name'][$i] . ' is uploaded!<br />';
}
}
}
?>
<html>
<head>
<title>.: Multiple Upload Example :.</title>
<script language="javascript" type="text/javascript">
function addNewField(){
var holder = document.getElementById('uploadholder');
var row = document.createElement('tr');holder.appendChild(row);
var field = document.createElement('td');row.appendChild(field);
field.innerHTML = '<input type="file" name="data[]" id="" />';
}
</script>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<table id="uploadholder">
<!--<tr><td><input type="file" name="data[]" id="" /></td></tr>-->
</table>
<input type="button" name="tambah" value="Add Field" onclick="javascript:addNewField()" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
-
http://www.harouny.com/ harouny
-
http://www.harouny.com harouny
-
http://gonde.freevar.coom/ gondez
-
http://gonde.freevar.coom gondez
-
v
-
v
-
http://zhac21.multiply.com/ Zhac
-
http://zhac21.multiply.com Zhac
-
martianman
-
martianman
-
Mipi
-
Mipi








