var upload = function(){
if(_file.files.length === 0){
return;
}
var data = new FormData();
data.append('SelectedFile', _file.files[0]);
var request = new XMLHttpRequest();
request.onreadystatechange = function(){
if(request.readyState == 4){
try {
var resp = JSON.parse(request.response);
} catch (e){
var resp = {
status: 'error',
data: 'Unknown error occurred: [' + request.responseText + ']'
};
}
console.log(resp.status + ': ' + resp.data);
}
};
request.upload.addEventListener('progress', function(e){
_progress.style.width = Math.ceil(e.loaded/e.total) * 100 + '%';
}, false);
request.open('POST', 'upload.php');
request.send(data);
}
上傳邏輯我每次運行用戶選擇什麼功能,但如果用戶選擇多個文件,我只得到了第一個文件。
接下來,如何調整大小?我不明白在這裏的代碼http://stackoverflow.com/questions/10333971/html5-pre-resize-images-before-uploading – user3346088
這裏都解釋了這裏:http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader /使用canvas對象調整圖像大小後,可以使用canvas.toDataURL()檢索圖像。如果你需要更多的信息,你必須在SO上創建一個單獨的線程,我猜 –