댓글에 첨부파일을 많이 넣어야 해서 구글 검색으로 파일추가버튼을 코드를 넣었습니다.
그런데 파일 인식은 하는데 업로드는 하나뿐이 안됩니다. 마지막 파일만 화면에 보여집니다.
어떻게 해야 할 지 알려주실수 있을까요? 코드는 다음과 같습니다.
<div class="comments-field field-file">
<div id="comment_file">
<input type="file" id="comment_file" name="comment_attach_file" value="upload" size="40">
<input type="button" value="추가" onclick="attachFile.add()" style="margin-left:5px; font-size:12px" >
</div>
</div>
<script language="JavaScript">
attachFile = {
idx:0,
add:function(){ // 파일필드 추가
var o = this;
var idx = o.idx;
var div = document.createElement('div');
div.style.marginTop = '3px';
div.id = 'file' + o.idx;
var file = document.all ? document.createElement('<input name="comment_attach_file">') : document.createElement('input');
file.type = 'file';
file.name = 'comment_attach_file' ;
file.size = '40';
file.id = 'filefield' + o.idx;
var btn = document.createElement('input');
btn.type = 'button';
btn.value = '삭제';
btn.onclick = function(){o.del(idx)}
btn.style.marginLeft = '5px';
div.appendChild(file);
div.appendChild(btn);
document.getElementById('comment_file').appendChild(div);
o.idx++;
},
del:function(idx){ // 파일필드 삭제
if(document.getElementById('fileField' + idx).value != '' && !confirm('삭제 하시겠습니까?')){
return;
}
document.getElementById('comment_file').removeChild(document.getElementById('file' + idx));
}
}
</script>