【问题标题】:EXTJS & PHP Upload fileEXTJS & PHP 上传文件
【发布时间】:2012-01-12 21:01:48
【问题描述】:

我在 EXTJS (http://dev.sencha.com/deploy/dev/examples/form/file-upload.html) 中使用 UploadFile 示例,但我不知道在服务器端写什么来保存上传的文件(在 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();
        }
    }]
});

【问题讨论】:

    标签: php file-upload extjs


    【解决方案1】:

    这里是一个例子,你可以使用它并根据你的需要进行定制。

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

    【讨论】:

    • 问题是在我的客户端,上传一直在运行,但是我的服务器中没有任何东西
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 2013-01-04
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多