0
我想讀取由我的AJAX上傳表單上傳的$ _FILES。這是POST請求:
POST myhost.net/csv.php
Host: myhost.net
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: application%2Fjson%2C%20text%2Fjavascript%2C%20*%2F*%3B%20q%3D0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
X-File-Name: Europe_1351.csv
Content-Type: multipart/form-data; charset=UTF-8
Pragma: no-cache
Cache-Control: no-cache
Referer: http://myhost.net
Content-Length: 26
Cookie: PHPSESSID=kourjvs7rm980d2cg4qvaav965
Connection: keep-alive
而在服務器端,我得到:
var_dump($_FILES);
即使 '的multipart/form-data的' 設置,沒有在$ _FILES任何數據變量。這是否與PHP配置有關?謝謝!
編輯:
這裏是我的代碼:
<script src="//raw.githubusercontent.com/LPology/Simple-Ajax-Uploader/master/SimpleAjaxUploader.js">
$(document).ready(function()
{
var sizeBox = document.getElementById('sizeBox');
var uploader = new ss.SimpleUpload({
button: 'uploadButton', // file upload button
url: 'csv.php', // server side handler
name: 'uploadfile', // upload parameter name
contentType: 'multipart/form-data',
responseType: 'json',
allowedExtensions: ['csv'],
maxSize: 10 * 1024, // kilobytes
hoverClass: 'ui-state-hover',
focusClass: 'ui-state-focus',
disabledClass: 'ui-state-disabled',
onSubmit: function(filename, extension)
{
this.setFileSizeBox(sizeBox); // designate this element as file size container
},
onComplete: function(filename, response)
{
if (!response) {
alert(filename + 'upload failed');
return false;
}
alert('file ' + response.data + ' uploaded successfully ');
// do something with response...
}
});
});
</script>
<div id='uploadButton'>
CSV
</div>
<div id='sizeBox'>
size
</div>
好的..請把你的代碼 –
我覺得函數是var_dump($ _FILES)而不是dump($ _FILES); –
@innovativekundan我更新了我的問題,謝謝! – user3578847