我有以下腳本,它允許通過PHP腳本將文件上傳到我的Web服務器,但我希望將僞代碼轉換爲純動作腳本。另外,出於某種原因,我的進度欄不顯示文件上傳的實際進度。Adobe Flex轉爲純動作腳本。怎麼樣?
這裏是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>
你爲什麼期待您的進度條來改變,因爲你什麼都不做是什麼? – 2012-01-10 05:59:19
代碼工作,似乎有ProgressEvent的事件監聽器,但我猜PHP不會報告文件上傳進度,因此Action Script只能看到開始和結束。我想我只會拋出一個微調。 – ASPiRE 2012-01-10 14:48:51