通常,我們從$ this-> request-> data獲取所需的所有數據。但如果我使用AJAX文件上傳,我無法獲得這些數據例如:tmp_name的值,大小等
我的javascript代碼如下:
function uploadFile(file_blob_chunk, file_name, file_part, total_file_chunk, file_id) {
fd = new FormData();
fd.append("file_for_upload", file_blob_chunk);
fd.append("somestring", "This is some extra data");
xhr = new XMLHttpRequest();
xhr.open("POST", "files/index/" + file_id + '/' + file_part, true);
//Onload happened after file finished uploaded
xhr.onload = function(e) {
//alert(file_name + "done");
};
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
}}, false);
xhr.send(fd);
}
和FilesController.php
public function index($file_id = null, $file_part = null) {
if ($this->request->is('post')) {
//I can't use $this->request->data, to get the file details
}
}
如果我使用
debug($this->request->data);
我只會變得
array(
'somestring' => 'This is some extra data'
)
我不能得到的文件數據
除非即時通訊使用的調試($ _ FILES),我不會得到
array(
'file_for_upload' => array(
'name' => 'blob',
'type' => 'application/octet-stream',
'tmp_name' => 'C:\xampp\tmp\phpAC42.tmp',
'error' => (int) 0,
'size' => (int) 9304862
)
)
轉到源? [Superglobals](http://php.net/manual/en/language.variables.superglobals.php)假設「框架」不剝奪它們。 – ficuscr