IT干货网

php之EXTJS & PHP 上传文件

lyj 2025年12月25日 编程设计 73 0

我在 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(); 
        } 
    }] 
}); 

请您参考如下方法:

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

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


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!