JAVASCRIPT jQuery + PHP 다중 파일 업로드 ( 간단 ) 

testa.html ------------------------------------------------------------------------------------ 
<script>
 
$('#upload').click(function() {
    var filedata = document.getElementsByName("file"),
            formdata = false;
    if (window.FormData) {
        formdata = new FormData();
    }
    var i = 0, len = filedata.files.length, img, reader, file;
 
    for (; i < len; i++) 
	{
        file = filedata.files[i];
        if (window.FileReader) 
		{
            reader = new FileReader();
            reader.onloadend = function(e) 
			{
                showUploadedItem(e.target.result, file.fileName);
            };
            reader.readAsDataURL(file);
        }
    }
 
</script>

<iframe name="my_iframe" src="" width="0" height="0" style="display:none"></iframe>
<form enctype="multipart/form-data" action="./testb.html" method="post" name='myiframe' target="my_iframe">
 
<table height=100%>
	<tr><td><input type="file" id="file[]" name='file[]'></td><td><input type="file" id="file[]" name='file[]'></td></tr>
	<tr><td height=8></td></tr>
	<tr><td><input type="file" id="file[]" name='file[]'></td><td><input type="file" id="file[]" name='file[]'></td></tr>
	<tr><td height=8></td></tr>
	<tr><td><input type="file" id="file[]" name='file[]'></td><td><button class="add_more btn btn-xs btn-primary">File Upload</button></td></tr>
	<tr><td height=8></td></tr>
</table>
</form>

---------------------------------------------------------------------------------------------
testb.html -------------------------------------------------------------------------------

<?php
 
$success_value = 0 ;
// $filename = array();
for($i=0; $i<count($_FILES['file']['name']); $i++){
    $target_path = "/home/..your account../images/";
    $ext = explode('.', basename( $_FILES['file']['name'][$i]));
    $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext)-1]; 
 
		if(move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) 
		{
                     echo "$target_path <br>";
		} 
		else
		{
 
		}
}
 
?>

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다