use*_*857 5 php file-upload extjs4
我正在研究extjs + php中的文件上传功能.我想从extjs上传文件或图像,需要将它发送到我在PHP设计的服务器端.在extjs中,我有查看文件的代码 -
Ext.define('Balaee.view.kp.dnycontent.Content',
{
extend:'Ext.panel.Panel',
requires:[
'Balaee.view.kp.dnycontent.ContentView'
],
id:'ContentId',
alias:'widget.Content',
title:'This day in a history',
items:[
{
xtype: 'fileuploadfield',
hideLabel: true,
emptyText: 'Select a file to upload...',
id: 'upfile',
//name:'file',
width: 220
}],
buttons:[
{
text: 'Upload',
handler: function () {
var file = Ext.getCmp('upfile').getEl().down('input[type=file]').dom.files[0]; console.log(file);
var reader = new FileReader();
filecontent=reader.readAsBinaryString(file);
console.log(filecontent);
}
}
]
Run Code Online (Sandbox Code Playgroud)
});
因此,当我尝试使用上面的代码上传animage文件.上面一行:
Ext.getCmp('upfile').getEl().down('input[type=file]').dom.files[0];将文件的信息存储为:
File {
webkitRelativePath: "",
lastModifiedDate: Tue Jul 14 2009 11:02:31 GMT+0530 (India Standard Time),
name: "Koala.jpg",
type: "image/jpeg",
size: 780831…
}
Run Code Online (Sandbox Code Playgroud)
即检索与文件有关的信息.但是没有检索到实际的文件内容.那么我需要修改什么来获取实际上传的文件?
文件的内容不会从 中返回readAsBinaryString,您必须设置读取文件内容时将触发的 onload 回调。
reader.onload = function (oFREvent) {
console.log(oFREvent.target.result);
};
Run Code Online (Sandbox Code Playgroud)