废话少说,先看flash代码,在flash中新建一个文档,放上两个button,一个progressbar组件: import flash.net.FileReference; import mx.controls.Alert; var my_pb:mx.controls.ProgressBar; var maxSize = 1000*1000*5; //文件大小限制:5M //设置进度栏模式 my_pb.mode = "manual"; my_pb.label = "上传进度:%1%"; //进度栏增加前的最小数值 my_pb.minimum = 0; // 进度栏停止前的最大值 my_pb.maximum = 100; var increment_num:Number = my_pb.minimum; var allTypes:Array = new Array(); var imageTypes:Object = new Object(); imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)"; imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png"; allTypes.push(imageTypes); var textTypes:Object = new Object(); textTypes.description = "Text Files (*.txt, *.rtf)"; textTypes.extension = "*.txt;*.rtf"; allTypes.push(textTypes); var flvType:Object =new Object(); flvType.description ="flv Files (*.flv)"; flvType.extension ="*.flv"; allTypes.push(flvType); // 定义警告确认后的动作。 var myClickHandler:Function = function (evt_obj:Object) { if (evt_obj.detail == Alert.OK) { trace("start stock app"); } }; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("onSelect: " + file.name); //if(!file.upload("http://localhost/upfiles/hlp.php")) { // trace("Upload dialog failed to open."); //} if (file.size<=maxSize) { //strState.text = "您选择得文件:" + file.name + "\n"; btnUpload.enabled = true; }else { msg( "对不起您选择的文件太大!"); btnUpload.enabled = false; } } listener.onCancel = function(file:FileReference):Void { trace("onCancel"); } listener.onOpen = function(file:FileReference):Void { trace("onOpen: " + file.name); } listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); my_pb.setProgress ((bytesLoaded / bytesTotal) * 100, my_pb.maximum); } listener.onComplete = function(file:FileReference):Void { trace("onComplete: " + file.name); msg("上传完毕!"); } listener.onHTTPError = function(file:FileReference):Void { trace("onHTTPError: " + file.name); msg("onHTTPError: " + file.name); } listener.onIOError = function(file:FileReference):Void { trace("onIOError: " + file.name); msg("onIOError: " + file.name); } listener.onSecurityError = function(file:FileReference, errorString:String):Void { trace("onSecurityError: " + file.name + " errorString: " + errorString); msg("onSecurityError: " + file.name + " errorString: " + errorString); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); this.btnBrowse.onRelease = function () { fileRef.browse(allTypes); }; this.btnUpload.onRelease = function () { if(!fileRef.upload("http://localhost/upfiles/upfile3.php")) { trace("Upload dialog failed to open."); } // 显示警告对话框。 } function msg(msgtxt:String) { Alert.show(msgtxt, "消息", Alert.OK , this, myClickHandler, "stockIcon", Alert.OK); } php文件很简单: <?php // Flash 传递的文件表单 name 属性为 Filedata $fileName = $_FILES["Filedata"]["name"]; $file = $_FILES["Filedata"]["tmp_name"]; $path = "uploadFiles/"; if (move_uploaded_file($file, $path . $fileName)){ // echo 1; }else{ // echo 0; } ?> |
联系客服