Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File upload with extjs4

i am working on Extjs4 file upload control. i have view with file upload control as-

Ext.define('Balaee.view.kp.dnycontent.Content', 
{
    extend:'Ext.form.Panel',
    requires:[
              'Balaee.view.kp.dnycontent.ContentView'
              ],
    id:'ContentId',
    alias:'widget.Content',
    enctype : 'multipart/form-data', 
    title:'This day in a history',
    items:[

    {
        xtype: 'fileuploadfield',
        hideLabel: true,
        emptyText: 'Select a file to upload...',
        //inputType: 'file',
        id: 'upfile',
        width: 220
}],
   buttons: [{
        xtype : 'button',
        fieldlabel:'upload',
        action:'upload',
        name:'upload',
        text: 'Upload',
        formBind:'true'

    }]
});

And corresponding action in controller is-

getUpload : function() {

        var file10 = Ext.getCmp('ContentId').getEl().down('input[type=file]').dom.files[0];

        var reader = new FileReader();
        reader.onload = function(oFREvent) {
            fileobj=oFREvent.target.result;
            console.log(oFREvent.target.result);

        };
        }
    });

So above controller's function is retriving uploaded file and displaying it in encoded format inside reader's onload function. i.e. "console.log(oFREvent.target.result);" line is displaying uploaded file's data in encoded format in console. I need to send this file to server side. So i am passing above fileobj as parameter to store as-

var storeObj=this.getStore('kp.DnycontentStore');
         storeObj.load({
         params:{
         data:fileobj
         },
         callback: function(records,operation,success){
           console.log("send");
         },
         scope:this
         })

But its showing fileobj as undefined outside reader.onload function. So how to send this file along with its contents to server side? Is there any other way to get uploaded file in controller and send it to server. Please can someone guide me.

like image 647
user1722857 Avatar asked Nov 13 '22 07:11

user1722857


1 Answers

I dont know how to handle fileuplaod on php side, but the return response from the server needs to be text/html encoded See the docs on this: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.Basic-method-hasUpload

also example PHP fileupload script: http://www.w3schools.com/php/php_file_upload.asp

like image 106
dbrin Avatar answered Dec 05 '22 13:12

dbrin