EXTJS & PHP Upload file

2019-07-20 18:14发布

I use the UploadFile example in EXTJS (http://dev.sencha.com/deploy/dev/examples/form/file-upload.html) but I don't know what to write in the server side to save the uploaded file (in php) help me please

My client side code is :

var fp = new Ext.FormPanel({
    //renderTo: 'fi-form',
    fileUpload: true,
    width: 500,
    frame: true,
    title: 'File Upload Form',
    autoHeight: true,
    bodyStyle: 'padding: 10px 10px 0 10px;',
    labelWidth: 50,
    defaults: {
        anchor: '95%',
        allowBlank: false,
        msgTarget: 'side'
    },
    items: [{
        xtype: 'fileuploadfield',
        id: 'form-file',
        emptyText: 'Select an image',
        fieldLabel: 'Photo',
        name: 'photo-path',
        buttonText: '',
        buttonCfg: {
            iconCls: 'upload-icon'
        }
    }],
    buttons: [{
        text: 'Save',
        handler: function(){
            if(fp.getForm().isValid()){
                    fp.getForm().submit({
                        url: 'php/file-upload.php',
                        waitMsg: 'Uploading your photo...',
                        success: function(fp, o){
                            msg('Success', 'Processed file');
                        }
                    });
            }
        }
    },{
        text: 'Reset',
        handler: function(){
            fp.getForm().reset();
        }
    }]
});

2条回答
家丑人穷心不美
3楼-- · 2019-07-20 19:13

Here is a example, you can use it and customize based on your needs.

if(isset($_FILES)){
  $temp_file_name = $_FILES['your_file']['tmp_name'];
  $original_file_name = $_FILES['your_file']['name'];

  // Find file extention
  $ext = explode ('.', $original_file_name);
  $ext = $ext [count ($ext) - 1];

  // Remove the extention from the original file name
  $file_name = str_replace ($ext, '', $original_file_name);

  $new_name = '_'.$file_name . $ext;

  if (move_uploaded_file ($temp_file_name, $new_name)) {
      echo "success";
   } else {
      echo "error";
    }

}
查看更多
登录 后发表回答