⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multifileupload.as

📁 多文件上传,前面flex界面.后台php处理的,可自己修改成java
💻 AS
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	Multi-File Upload Component Ver 1.1
//
//  Copyright (C) 2006 Ryan Favro and New Media Team Inc.
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//	of the License, or (at your option) any later version.
//	
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//	
//	You should have received a copy of the GNU General Public License
//	along with this program; if not, write to the Free Software
//	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//	Any questions about this component can be directed to it's author Ryan Favro at ryanfavro@hotmail.com
//
//  To use this component create a new instance of this component and give it ten parameters
//
//	EXAMPLE:
//
//	multiFileUpload = new MultiFileUpload(
//	      filesDG,   		// <-- DataGrid component to show the cue'd files
//	      browseBTN, 		// <-- Button componenent to be the browser button
//	      clearButton, 		// <-- Button component to be the button that removes all files from the cue
//	      delButton, 		// < -- Button component to be the button that removes a single selected file from the cue
//	      upload_btn, 		// <-- Button component to be the  button that triggers the actual file upload action
//	      progressbar, 		// <-- ProgressBar Component that will show the file upload progress in bytes
//	      "http://[Your Server Here]/MultiFileUpload/upload.cfm", // <-- String Type the url to the server side upload component can be a full domain or relative
//	      postVariables,  	// < -- URLVariables type that will contain addition variables to accompany the upload
//	      350000, 			//< -- Number type to set the max file size for uploaded files in bytes. A value of 0 (zero) = no file limit
//	      filesToFilter 	// < -- Array containing FileFilters an empty Array will allow all file types
//	       );
//
//
//
//	Enjoy!
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////




package com.newmediateam.fileIO {

	// Imported Class Definitions
    import mx.controls.DataGrid;
    import mx.controls.Button;
    import mx.controls.ProgressBar;
    import mx.controls.ProgressBarMode;
    import mx.controls.dataGridClasses.*;
    import mx.controls.Alert;
    import mx.events.CollectionEvent;
    import mx.collections.ArrayCollection;
    import flash.events.*;
    import flash.net.FileReferenceList;
    import flash.net.FileFilter;
    import flash.net.FileReference;
    import flash.net.URLRequest;
    import flash.net.URLVariables;

    
    
    public class MultiFileUpload {
    
    	
    	
        //UI Vars
        private var _datagrid:DataGrid;
        private var _browsebutton:Button;
        private var _remselbutton:Button;
        private var _remallbutton:Button;
        private var _uploadbutton:Button;
        private var _progressbar:ProgressBar;
        private var _testButton:Button;

        //DataGrid Columns
        private var _nameColumn:DataGridColumn;
        private var _typeColumn:DataGridColumn;
        private var _sizeColumn:DataGridColumn;
        private var _creationDate:DataGridColumn;
        private var _modificationDate:DataGridColumn;
        private var _progressColumn:DataGridColumn;
        private var _columns:Array;
        
        //File Reference Vars
        [Bindable]
        private var _files:ArrayCollection;
        private var _fileref:FileReferenceList
        private var _file:FileReference;
        private var _uploadURL:URLRequest;
        private var  _totalbytes:Number;
        
        //File Filter vars
        private var _filefilter:Array;

        //config vars
        private var _url:String; // location of the file upload handler can be a relative path or FQDM
        private var _maxFileSize:Number; //bytes
        private var _variables:URLVariables; //variables to passed along to the file upload handler on the server.
        
        //Constructor    
        public function MultiFileUpload(
        								dataGrid:DataGrid,
        								browseButton:Button,
        								removeAllButton:Button,
                                        removeSelectedButton:Button,
                                        uploadButton:Button,
                                        progressBar:ProgressBar,
                                        url:String,
                                        variables:URLVariables,
                                        maxFileSize:Number,
                                        filter:Array
                                        ){
            _datagrid = dataGrid;
            _browsebutton = browseButton;
            _remallbutton = removeAllButton;
            _remselbutton = removeSelectedButton;            
            _uploadbutton = uploadButton;
            _url = url;
            _progressbar = progressBar;
            _variables = variables;
            _maxFileSize = maxFileSize;
            _filefilter = filter;
            init();
        }
        
        //Initialize  Component
        private function init():void{
	        
	        // Setup File Array Collection and FileReference
	        _files = new ArrayCollection();
	        _fileref = new FileReferenceList;
	        _file = new FileReference;
	        
	        // Set Up Total Byes Var
	        _totalbytes = 0;
	        
	        // Add Event Listeners to UI 
	        _browsebutton.addEventListener(MouseEvent.CLICK, browseFiles);
	        _uploadbutton.addEventListener(MouseEvent.CLICK,uploadFiles);
	        _remallbutton.addEventListener(MouseEvent.CLICK,clearFileCue);
	        _remselbutton.addEventListener(MouseEvent.CLICK,removeSelectedFileFromCue);
	        _fileref.addEventListener(Event.SELECT, selectHandler);
	        _files.addEventListener(CollectionEvent.COLLECTION_CHANGE,popDataGrid);
	        
	        // Set Up Progress Bar UI
	        _progressbar.mode = "manual";
	        _progressbar.label = "";
	        
	        // Set Up UI Buttons;
	        _uploadbutton.enabled = false;
	        _remselbutton.enabled = false;
	        _remallbutton.enabled = false;
	        
	        
	        // Set Up DataGrid UI
	        _nameColumn = new DataGridColumn;
	        _typeColumn = new DataGridColumn;
	        _sizeColumn = new DataGridColumn;
	            
	        _nameColumn.dataField = "name";
	        _nameColumn.headerText= "File";
	        
	        _typeColumn.dataField = "type";
	        _typeColumn.headerText = "File Type";
	        _typeColumn.width = 80;
	        
	        _sizeColumn.dataField = "size";
	        _sizeColumn.headerText = "File Size";
	        _sizeColumn.labelFunction = bytesToKilobytes as Function;
	        _sizeColumn.width = 150;
	        
	        _columns = new Array(_nameColumn,_typeColumn,_sizeColumn);
	        _datagrid.columns = _columns
	        _datagrid.sortableColumns = false;
	        _datagrid.dataProvider = _files;
	        _datagrid.dragEnabled = true;
	        _datagrid.dragMoveEnabled = true;
	        _datagrid.dropEnabled = true;
	    	
	    	// Set Up URLRequest
	        _uploadURL = new URLRequest;
	        _uploadURL.url = _url;
	        _uploadURL.method = "GET";  // this can also be set to "POST" depending on your needs 
	        
	        _uploadURL.data = _variables;
	        _uploadURL.contentType = "multipart/form-data";
	        
	        
        }
        
        /********************************************************
        *   PRIVATE METHODS                                     *
        ********************************************************/
        
        
        //Browse for files
        private function browseFiles(event:Event):void{        
                
                _fileref.browse(_filefilter);
                
            }

		//Upload File Cue
        private function uploadFiles(event:Event):void{
           
            if (_files.length > 0){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -