簡體   English   中英

如何在PHP中使用Ajax捕獲上傳的文件

[英]How to catch files uploaded using ajax with PHP

我有這個JavaScript代碼可以上傳文件

// Uploading - for Firefox, Google Chrome and Safari
xhr = new XMLHttpRequest();

xhr.open("post", "pro/upload.php", true);

// Set appropriate headers
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.setRequestHeader("X-File-Name", file.fileName);
xhr.setRequestHeader("X-File-Size", file.fileSize);
xhr.setRequestHeader("X-File-Type", file.type);

// Send the file (doh)
xhr.send(file);

現在如何在upload.php捕獲文件?

我嘗試使用全局$_FILES["file"]變量,但是出現錯誤消息“ Undefined Index”。 這是否意味着未設置全局變量?

您還應該在setRequestHeader引用鏈接中傳遞Content-Disposition: Content-Disposition參考

我正在使用對我來說完美的Ajax文件上傳,並且易於實現,如果您想使用jQuery,請選擇此鏈接。

http://www.phpletter.com/Demo/AjaxFileUpload-Demo/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM