UploadFile.fla
// 加载包
import flash.net.FileReference;
// 定义主角 FileReference 对象
var fileRef:FileReference = new FileReference();
// 定义 监听对象
var fileLsn: Object = new Object ();
// 定义 文件类型数组 FileReference 对象的 browse 方法的参数
// description: 描述
// extension : 扩展名列表
var fileTyp: Array = new Array ({description: " Image files " , extension: " *.jpg;*.gif " }, {description: " Document files " , extension: " *.txt;*.doc " });
btnBrowse.onRelease = function () {
// 打开 " 选择文件 " 对话框
fileRef.browse(fileTyp);
};
btnUpload.onRelease = function () {
// 开始上传
fileRef.upload( " uploadFile.php " );
};
btnClear.onRelease = function () {
strState.text = "" ;
};
// 选择文件事件
fileLsn.onSelect = function (file:FileReference) {
strState.text += " onSelect ' " + file.name + " '\n " ;
};
// 取消选择
fileLsn.onCancel = function (file:FileReference) {
strState.text += " Cancel!\n " ;
};
// 打开文件开始上传
fileLsn.onOpen = function (file:FileReference) {
strState.text += " Uploading ' " + file.name + " '\n " ;
};
// 上传成功
fileLsn.onComplete = function (file:FileReference) {
strState.text += " File ' " + file.name + " ' upload successfull!\n " ;
};
// 上传过程
fileLsn.onProgress = function (file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
strState.text += " onProgress: " + file.name + " with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal + " \n " ;
};
// HTTP 错误
fileLsn.onHTTPError = function (file:FileReference, httpError:Number) {
strState.text += " HTTP ERROR: " + httpError + " \n " ;
};
// IO 错误
fileLsn.onIOError = function (file:FileReference):Void {
strState.text += " IO Error: " + file.name + " \n " ;
};
// 安全错误
fileLsn.onSecurityError = function (file:FileReference, errorString: String ):Void {
strState.text += " onSecurityError: " + file.name + " errorString: " + errorString;
};
// 绑定监听器
fileRef.addListener(fileLsn);
// 其他属性或事件请参考帮助中关于 FileReference 对象的章节
[Copy to clipboard]
UploadFile.php
CODE:
< ?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 ;
}
/*
* 只要上传代码就够了
* Flash 似乎不判断该文件的返回值
* 即使该文件报告错 Flash 也无法分析
* 所以最好保证这个文件不会出错
*/
? >
// 加载包
import flash.net.FileReference;
// 定义主角 FileReference 对象
var fileRef:FileReference = new FileReference();
// 定义 监听对象
var fileLsn: Object = new Object ();
// 定义 文件类型数组 FileReference 对象的 browse 方法的参数
// description: 描述
// extension : 扩展名列表
var fileTyp: Array = new Array ({description: " Image files " , extension: " *.jpg;*.gif " }, {description: " Document files " , extension: " *.txt;*.doc " });
btnBrowse.onRelease = function () {
// 打开 " 选择文件 " 对话框
fileRef.browse(fileTyp);
};
btnUpload.onRelease = function () {
// 开始上传
fileRef.upload( " uploadFile.php " );
};
btnClear.onRelease = function () {
strState.text = "" ;
};
// 选择文件事件
fileLsn.onSelect = function (file:FileReference) {
strState.text += " onSelect ' " + file.name + " '\n " ;
};
// 取消选择
fileLsn.onCancel = function (file:FileReference) {
strState.text += " Cancel!\n " ;
};
// 打开文件开始上传
fileLsn.onOpen = function (file:FileReference) {
strState.text += " Uploading ' " + file.name + " '\n " ;
};
// 上传成功
fileLsn.onComplete = function (file:FileReference) {
strState.text += " File ' " + file.name + " ' upload successfull!\n " ;
};
// 上传过程
fileLsn.onProgress = function (file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
strState.text += " onProgress: " + file.name + " with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal + " \n " ;
};
// HTTP 错误
fileLsn.onHTTPError = function (file:FileReference, httpError:Number) {
strState.text += " HTTP ERROR: " + httpError + " \n " ;
};
// IO 错误
fileLsn.onIOError = function (file:FileReference):Void {
strState.text += " IO Error: " + file.name + " \n " ;
};
// 安全错误
fileLsn.onSecurityError = function (file:FileReference, errorString: String ):Void {
strState.text += " onSecurityError: " + file.name + " errorString: " + errorString;
};
// 绑定监听器
fileRef.addListener(fileLsn);
// 其他属性或事件请参考帮助中关于 FileReference 对象的章节
[Copy to clipboard]
UploadFile.php
CODE:
< ?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 ;
}
/*
* 只要上传代码就够了
* Flash 似乎不判断该文件的返回值
* 即使该文件报告错 Flash 也无法分析
* 所以最好保证这个文件不会出错
*/
? >