我正在尝试在
Adobe Flash CS3上的 Flash 动作脚本 3.0 中开发多个文件上传脚本
这是我的代码:-
FLASH 动作脚本:
import flash.net.FileReferenceList;
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.FileReference;
var fileRef:FileReferenceList = new FileReferenceList();
var uploadURL:URLRequest = new URLRequest();
var uploadPhotoScript:String = "http://localhost/as3/1.php";
uploadURL.url = uploadPhotoScript;
var totalFiles:int = 0;
btn_browse.addEventListener(MouseEvent.CLICK, onUploadClicked);
function onUploadClicked(e:MouseEvent):void
{
fileRef = new FileReferenceList();
fileRef.browse(new Array( new FileFilter( "Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg;*.jpeg;*.gif;*.png" )));
fileRef.addEventListener(Event.SELECT, fileSelectHandler);
}
function fileSelectHandler(event:Event):void {
for each(var fileToUpload:FileReference in fileRef.fileList){
++totalFiles;
uploadSingleFile(fileToUpload);
}
}
function uploadSingleFile(file:FileReference):void {
file.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
file.addEventListener(Event.COMPLETE, onFileUploadComplete);
progressBar.width=2;
file.upload(uploadURL);
file.addEventListener(Event.COMPLETE, completeHandler);
}
function onUploadProgress(e:ProgressEvent):void
{
var f:FileReference = e.currentTarget as FileReference;
var fileName:String = f.name;
var progres:Number = (e.bytesLoaded / e.bytesTotal) * 100;
progressBar1.width=3.5*(progres);
txt_curr.text=""+fileName+"";
prog1.text=""+progres+" %"
}
function completeHandler(event:Event):void {
trace("upload complete");
}
function onFileUploadComplete(e:Event):void
{
--totalFiles;
if(totalFiles == 0){
trace("all file uploaded Successfully !");
progressBar.width=100*3.5;
}
}
其中btn_browse 是添加到movie 和progressBar 的按钮,progressBar1 也是用于分别显示所有文件和当前正在上传的文件的进度的符号。txt_curr 是一个文本框,显示当前正在处理的文件的名称。
PHP:
<?php
if(!empty($_FILES)){
$tmpfile = $_FILES['Filedata']['tmp_name'];
$targetfile = "images/" . $_FILES['Filedata']['name'];
move_uploaded_file($tmpfile, $targetfile);
}
?>
现在我想要的是:
任何人都可以帮助我吗?我是 Flash 新手,正在努力学习它。提前致谢。