0
formData 객체에 추가 정보를 추가하는 데 어려움이 있으므로 PHP에서 SQL 데이터베이스에 추가 할 수 있습니다. 불행히도 AJAX를 사용하여 서버 나 로컬 호스트에서 실행할 필요가 있는지 테스트 할 수 있지만 'StackedTest.php'라는 간단한 PHP 파일이 포함되어 있습니다.이 formData 객체에 새 값을 추가하는 데 문제가 있습니다.
다음 예제는 다음과 같습니다. MDN하지만 많은 시간을 들여서 답을 찾다가 아무 것도 얻지 못했습니다. 어떤 도움
감사합니다. 파일 슈퍼 글로벌은 다음과 같습니다
<html>
<head>
<script type="text/javascript">
var returned;
var fd;
function ajaxCall(sends){
fd = new FormData();
var images = document.getElementById('images');
fd.append('file', images.files[0]);
/**
**
** This doesn't seem to be working, I am trying to append the value of the select box ** to the FILES array
** so I can use it in php to add to an SQL database.
**
**/
fd.append('catagory', document.getElementById('cat').value);
var ajax=new XMLHttpRequest();
ajax.onreadystatechange=function(){
if (ajax.readyState==4 && ajax.status==200){
document.getElementById("response").innerHTML = ajax.response;
fd = null;
}
}
ajax.open("POST","Stackedtest.php",true);
ajax.send(fd);
}
</script>
</head>
<body>
<div id="content">
<div>
<form method="post" enctype="multipart/form-data" action="?">
<select name="cat" id="cat"><br>
<option value="opt1">option 1</option>
<option value="opt2">option 2</option>
<option value="opt3">option 3</option>
</select><br>
<input type="file" name="images[]" id="images" multiple /><br>
<button type="button" id="btn" onclick="ajaxCall()">Upload Files!</button>
</form>
<p id="response">Response text here</p>
</div>
</div> <!-- END CONTENT -->
</body>
</html>
PHP 스크립트
<?php
if(isset($_FILES['file'])){
print_r($_FILES['file']);
print_r($_FILES['catagory']);
}
?>
그 덕분에 완벽하게 작동했습니다. – synthet1c