我有以下脚本允许文件通过PHP脚本上传到我的Web服务器,但我希望将伪代码转换为纯动作脚本。此外,由于某种原因,我的进度条不会显示文件上传的实际进度。
以下是PHP代码:
<?php
$tempFile = $_FILES['Filedata']['tmp_name'];
$fileName = $_FILES['Filedata']['name'];
$fileSize = $_FILES['Filedata']['size'];
move_uploaded_file($tempFile, "./" . $fileName);
?>
以下是Adobe Flex代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="225" height="178" minWidth="955" minHeight="600">
<fx:Declarations>
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.net.FileReference;
public var fileRef:FileReference = new FileReference();
public function uploadDialog(e:MouseEvent):void{
errLabel.text="";
var imgType:FileFilter = new FileFilter("Images (*.GIF,*.JPG,*.PNG)","*.gif;*.jpg;*.png");
var filterArray:Array=new Array(imgType);
fileRef.browse(filterArray);
fileRef.addEventListener(Event.SELECT,fileSelect);
fileRef.addEventListener(ProgressEvent.PROGRESS,fileProgress);
fileRef.addEventListener(Event.COMPLETE,fileComplete);
}
public function fileSelect(e:Event):void{
var fileURL:URLRequest = new URLRequest("upload.php");
try
{
//filepath.text=fileRef.name;
fileRef.upload(fileURL);
}
catch (err:Error)
{
errLabel.text="Unable to Upload File.....";
}
}
public function fileProgress(e:ProgressEvent):void
{
progBar.visible=true;
}
public function fileComplete(e:Event):void{
errLabel.text="File Uploaded Sucessfully....."
progBar.visible=false;
}
]]>
</fx:Script>
<s:Label x="10" y="10" click="uploadDialog(event)" text="Upload ..."/>
<mx:ProgressBar id="progBar" x="10" y="26"/>
<s:Label id="errLabel" x="10" y="108" width="200" text="..."/>
</s:Application>
答案 0 :(得分:0)
选中此example:您必须设置maximum
和minimum
属性,并在fileProgress
功能中致电setProgress
有两种方法可以将flex代码转换为纯as3:
*在flex-config.xml中设置<keep-generated-actionscript>true</keep-generated-actionscript>
*重写代码而不使用mxml作为纯as3项目
答案 1 :(得分:0)
这就是我在寻找有关进度条更新的内容。
private function progressHandler(event:ProgressEvent):void
{
pb.setProgress(event.bytesLoaded, event.bytesTotal);
}
解决方案的链接。