【发布时间】:2012-01-10 05:23:11
【问题描述】:
我有以下脚本,它允许通过 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>
【问题讨论】:
-
既然您什么都不做,为什么还要期待进度条发生变化?
-
代码有效,似乎 ProgressEvent 有一个事件侦听器,但我猜 PHP 不会报告文件上传进度,因此 Action Script 只看到开头和结尾。我想我只会扔一个微调器。
标签: actionscript-3 apache-flex flex4 flex3 flex4.5