Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs - upload file using filefield

My extjs code like http://www.objis.com/formationextjs/lib/extjs-4.0.0/docs/api/Ext.form.field.File.html

Ext.create('Ext.form.Panel', {
    title: 'Upload a Photo',
    width: 400,
    bodyPadding: 10,
    frame: true,
    renderTo: Ext.getBody(),    
    items: [{
        xtype: 'filefield',
        name: 'photo',
        fieldLabel: 'Photo',
        labelWidth: 50,
        msgTarget: 'side',
        allowBlank: false,
        anchor: '100%',
        buttonText: 'Select Photo...'
    }],

    buttons: [{
        text: 'Upload',
        handler: function() {
            var form = this.up('form').getForm();
            if(form.isValid()){
                form.submit({
                    url: 'photo-upload.php',
                    waitMsg: 'Uploading your photo...',
                    success: function(fp, o) {
                        Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
                    }
                });
            }
        }
    }]
});

my photo-upload.php file

echo "{success:true}";

But when success o.result.file show undefined. I think it will show file name after success.
How can i make it show file name after success thanks

like image 230
DeLe Avatar asked Jun 20 '13 08:06

DeLe


1 Answers

You are just returning "{success:true}" which is not even valid JSON but expect ExtJS to provide you with even more data?

Try to return JSON like

{ "success": true, "file": "filename" }

so that there is a file property in the result that the client can read.

like image 187
sra Avatar answered Sep 21 '22 15:09

sra