EXTJS& PHP上传文件

时间:2010-09-14 18:17:51

标签: php file-upload extjs

我使用EXTJS中的UploadFile示例(http://dev.sencha.com/deploy/dev/examples/form/file-upload.html),但我不知道在服务器端写什么来保存上传的文件(在php中) 请帮帮我

我的客户端代码是:

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 个答案:

答案 0 :(得分:6)

以下是一个示例,您可以根据自己的需要使用它并进行自定义。

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";
    }

}

答案 1 :(得分:2)