我正在尝试使用 AJAX 上传文件。如果我做一个vardump:
var_dump($_FILES);
我得到一个充满信息的数组。但如果我这样做:
$try = move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
$try 是假的谁能帮帮我?
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});
}
}
来自 $_FILES 的 var_dump
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)
}
}
谢谢