通常、必要なデータはすべて $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'
)
ファイルデータを取得できません
debug($_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
)
)