최근에 간단한 HTML5 드래그 앤 드롭을 이미 간단한 PHP 파일 업로드 스크립트에 추가하려고합니다. 튜토리얼 및 기타 솔루션을 많이 읽었지만 전체 파일을 서버 부분으로 보내는 것을 이해할 수없는 것 같습니다. 내가 이해 한 바로는 XMLHttpRequest가 데이터를 보내지 만 페이지를 다시로드하지 않고도이를 수행합니다. 이것은, 나는 원하지 않는다. 현재 사용중인 스크립트는 POST 데이터를 가져 와서 파일 업로드 출력을 생성합니다 (예 : 서버 다운로드 링크, 이미지의 경우 미리보기 이미지 등HTML5 자바 스크립트 POST 파일 업로드
드래그 앤 드롭으로 POST 데이터를 제출하고 업로드 출력에 액세스하거나 페이지를 다시로드하려면 어떻게해야합니까?
편집 : 나는 드래그 앤 드롭에 대해 다음을 사용하고 :
<div id="drop_zone">Drag and drop a file here</div>
<script>
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files; // FileList object.
uploadFile(files[0]); //<-- This is where most examples will use XMLHttpRequest to construct form and send data
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
document.getElementById('drop_zone').style.backgroundColor = "#faffa3";
evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
function handleDragLeave(evt) {
document.getElementById('drop_zone').style.backgroundColor = "";
}
// Setup the dnd listeners.
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
dropZone.addEventListener('dragleave', handleDragLeave, false);
</script>
코드는 어디에 있습니까? – PeeHaa
페이지를 다시로드하려면 XMLHttpRequest를 사용할 이유가 없습니다. 그냥 정규 양식 POST를하십시오. – Pointy
@Pointy 파일을 삭제 한 후 어떻게 파일 입력 필드를 설정할 수 있습니까? – CYMA