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条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?