0
我正尝试使用AJAX上传文件。 如果我做了vardump:使用AJAX和PHP上传
var_dump($_FILES);
我得到充满信息的数组。 但是,如果我这样做:
$try = move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
$尝试是假的谁可以帮我?
的javascript:
var formData = new FormData($('form')[0]);
$.ajax({
url: 'process.php?command=upload', //Server script to process data
type: 'POST',
xhr: function() { // Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // Check if upload property exists
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload
}
return myXhr;
},
//Ajax events
// beforeSend: beforeSendHandler,
//success: completeHandler,
//error: errorHandler,
// Form data
data: formData,
//Options to tell jQuery not to process data or worry about content-type.
cache: false,
contentType: false,
processData: false
});
});
function progressHandlingFunction(e){
if(e.lengthComputable){
$('progress').attr({value:e.loaded,max:e.total});
}
}
后续代码var_dump从$ _FILES
array(1) {
["file"]=>
array(5) {
["name"]=>
string(5) "1.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/phpATNNIs"
["error"]=>
int(0)
["size"]=>
int(220559)
}
}
感谢
和JavaScript代码在哪里? –
看这里http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/ –
你能否给我们$ _FILES的整个输出? –