在浏览器下面.ie很难检测文件大小.
好不容易 img 有个 函数可以..ie7 下面又不可以了..
没有办法.试验下 flex 到是大小出来了..
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" > <mx:Script> <![CDATA[ import flash.events.*; import flash.net.FileReference; import flash.net.URLRequest; import mx.controls.Alert; private var currentAction:String; private var uploadURL:URLRequest; private var file:FileReference; private var fileName:String; private function init() : void{ file = new FileReference(); } public function FileReference_browse() : void { currentAction = "upload"; uploadURL = new URLRequest(); file = new FileReference(); configureListeners(file); file.browse(); } private function configureListeners(dispatcher:IEventDispatcher):void { dispatcher.addEventListener(Event.SELECT, selectHandler); } private function selectHandler(event:Event):void { var file:FileReference = FileReference(event.target); Alert.show(file.size+""); } ]]> </mx:Script> <mx:Panel width="100%" height="100%"> <mx:VBox width="100%" horizontalAlign="center"> <mx:Label text="Click the below button to select a file which you want to upload!" /> <mx:Button label="Upload" click="FileReference_browse()" /> </mx:VBox> </mx:Panel> </mx:Application>
下面就是考虑如何和js进行交互了.
通过js得到file的长度.然后进行上传..然而也可以
用flex编写一个上传组件.