search
Homephp教程php手册Flash上传文件

上传

一直想搞这个功能, 想了很多歪门邪道, 未果!
昨天突然在 blueidea 上看到关于 Flash 8 的新特性 (虽然早就装上了 Flash 8 但一直没有仔细研究, 真是惭愧 :p) 中介绍了 flash 8 提供了上载和下载的接口, 马上下去研究了一下, 果然不错. 虽然上传还是需要后台脚本的支持, 但也足够我美上一阵子的了 :D
下面是研究成果, 不敢独享, 拿出来示众 :D
UploadFile.fla

CODE:
// 加载包
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 对象的章节


UploadFile.php

CODE:
// 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 也无法分析
* 所以最好保证这个文件不会出错
*/
?>
源文件下载
 



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor