2011-12-26 39 views
0

我这段JavaScript代码上传文件如何捕捉上传的文件使用Ajax和PHP

// 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"]可变的,但一个错误说“未定义指数”。这是否意味着全局变量未设置?

+0

您可以更新相关的HTML和PHP代码 – 2011-12-26 07:15:07

回答

0

我使用的是工作非常适合我的Ajax文件上传,这是很容易实现,如果你喜欢用jQuery工作请喜欢这个链接。

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