EXT 文件上传扩展组件简单介绍

EXT  扩展组件效果确实超酷,而且应用也非常简单,下面简单介绍一二.效果图如下:

老规矩,看代码吧。。

HTML代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Ext.ux.UploadDialog user extension.</title> <meta http-equiv="content-type" content="text/html; charset=utf-8">  <style type='text/css'>   @import url('../../resources/css/ext-all.css');   @import url('css/Ext.ux.UploadDialog.css');   @import url('lib/upload-dialog.css');  </style> <style type='text/css'>     #loading-mask     {       width:100%;       height:100%;       background:#c3daf9;       position:absolute;       z-index:20000;       left:0px;       top:0px;     }         #loading     {       position:absolute;       left:42%;       top:40%;       border:1px solid #6593cf;       padding:2px;       background:#c3daf9;       width:200px;       text-align:center;       z-index:20001;     }         #loading .loading-indicator     {       border:1px solid #a3bad9;       background: white;         background-position: 15px center;       color:#003366;       font:bold 13px tahoma,arial,helvetica;       padding:10px;       margin:0;     } </style> </head> <body style='overflow: hidden'>  <div id="loading-mask" style="width:100%;height:100%;background:#c3daf9;position:absolute;z-index:20000;left:0;top:0;">&#160;</div>

 <div id="loading" style="z-index: 20001; position: absolute">   <div class="loading-indicator">    <img src="UFimages/loading.gif" style="width:16px; height:16px; vertical-align: middle" alt="Loading indicator" />    &#160;Loading   </div>  </div>

   <div id='demo-panel'>   <h3>Demo panel</h3>   <div id='file-list'></div>   <div id='show-dialog-btn'>   </div>  </div>  

 

<script language="JavaScript"> <!--

function SymError() {   return true; }

window.onerror = SymError;

//--> </script>

<script type='text/javascript' src='lib/ext-base.js'></script>  <script type='text/javascript' src='lib/ext-all-debug.js'></script>  <script type='text/javascript' src='lib/Ext.ux.UploadDialog.js'></script>  <script type='text/javascript' src='lib/upload-dialog.js'></script> </body> </html>

 

核心JAVASCRIPT代码如下:

var UploadDialogController = function() {   var dialog = null;    var button = null;   var file_list_tpl = new Ext.Template(     "<div class='file-list-entry'>File {name} successfuly uploaded.</div>"   );   file_list_tpl.compile();

 function hideLoadingMask()  {   var loading = Ext.get('loading');   var mask = Ext.get('loading-mask');   mask.remove();   loading.remove();   Ext.get(document.body).setStyle('overflow', 'visible');  }

 function askUser()  {   return confirm('Are you sure?');  }

 function getDialog()  {   if (!dialog) {     dialog = new Ext.ux.UploadDialog.Dialog({    url: 'upload-dialog-request.php',    reset_on_hide: false,    proxyDrag: true,    allow_close_on_upload: true,    upload_autostart: false, //true,    post_var_name: 'file',    permitted_extensions: ['jpg', 'jpeg', 'gif', 'zip', 'rar']     });         dialog.on('uploadsuccess', onUploadSuccess); //    dialog.on('fileuploadstart',getfilename); //    dialog.on('filetest', askUser);   }   return dialog;  }    function showDialog(button)  {   getDialog().show(button.getEl());  }    function onUploadSuccess(dialog, filename, resp_data)  {   var parts = filename.split(///|///);   if (parts.length == 1) {     filename = parts[0];   }   else {     filename = parts.pop();   }   file_list_tpl.append('file-list', {name: filename});  }   // function getfilename(dialog, filename, resp_data) // { //  alert(filename);  // }    return {   init : function()   {     Ext.QuickTips.init();       button = new Ext.Button({    renderTo: 'show-dialog-btn',    id: 'show-button',    text: 'File Upload',    handler: showDialog     });       hideLoadingMask();     Ext.get(document.body).setStyle('overflow', 'auto');   }  } }();

Ext.BLANK_IMAGE_URL = 'UFimages/s.gif'; Ext.onReady(UploadDialogController.init);

 

AJAX请求的后台页面代码如下:

<?php $uploaddir = "upload/";//linux上传路径 $uploadfile =$uploaddir.time().$_FILES['file']['name']; $response = array(); if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {  $response['success'] = true;  $response['message'] = 'File uploaded successfully. File Size '.$_FILES['file']['size'].' Bytes'; } else {  $response['success'] = false;  $response['message'] = 'Some error occurred during file upload'; } echo json_encode($response); ?>


 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Configuration. Most configuration options are inherited from Ext.Window (see ExtJs docs). The added ones are: url - the url where to post uploaded files. base_params - additional post params (default to {}). permitted_extensions - array of file extensions which are permitted to upload (default to []). reset_on_hide - whether to reset upload queue on dialog hide or not (default true). allow_close_on_upload - whether to allow hide/close dialog during upload process (default false). upload_autostart - whether to start upload automaticaly when file added or not (default false). post_var_name - uploaded data POST variable name (defaults to 'file'). Events. filetest - fires before file is added into the queue, parameters: dialog - reference to dialog filename - file name If handler returns false then file will not be queued. fileadd - fires when file is added into the queue, parameters: dialog - reference to dialog filename - file name fileremove - fires when file is removed from the queue, parameters: dialog - reference to dialog filename - file name record - file record resetqueue - fires when upload queue is resetted, parameters: dialog - reference to dialog beforefileuploadstart - fires when file as about to start uploading: dialog - reference to dialog filename - uploaded file name record - file record If handler returns false then file upload will be canceled. fileuploadstart - fires when file has started uploading: dialog - reference to dialog filename - uploaded file name record - file record uploadsuccess - fires when file is successfuly uploaded, parameters: dialog - reference to dialog filename - uploaded file name data - js-object builded from json-data returned from upload handler response. record - file record uploaderror - fires when file upload error occured, parameters: dialog - reference to dialog filename - uploaded file name data - js-object builded from json-data returned from upload handler response. record - file record uploadfailed - fires when file upload failed, parameters: dialog - reference to dialog filename - failed file name record - file record uploadcanceled - fires when file upload canceled, parameters: dialog - reference to dialog filename - failed file name record - file record uploadstart - fires when upload process starts, parameters: dialog - reference to dialog uploadstop - fires when upload process stops, parameters: dialog - reference to dialog uploadcomplete - fires when upload process complete (no files to upload left), parameters: dialog - reference to dialog Public methods Better go see the source. I18n. The class is ready for i18n, override the Ext.ux.UploadDialog.Dialog.prototype.i18n object with your language strings, or just pass i18n object in config. Server side handler. The files in the queue are posted one at a time, the file field name is 'file'. The handler should return json encoded object with following properties:
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值