douhuang2673 2010-09-14 18:17
浏览 44
已采纳

EXTJS和PHP上传文件

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条回答 默认 最新

  • donh61500 2010-09-14 18:21
    关注

    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";
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料