Home php教程 php手册 Flash上传文件

Flash上传文件

Jun 21, 2016 am 09:07 AM
file function

上传

一直想搞这个功能, 想了很多歪门邪道, 未果!
昨天突然在 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 of this Website
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hongmeng native application random poetry Hongmeng native application random poetry Feb 19, 2024 pm 01:36 PM

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

How to convert php blob to file How to convert php blob to file Mar 16, 2023 am 10:47 AM

How to convert php blob to file: 1. Create a php sample file; 2. Through "function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })} ” method can be used to convert Blob to File.

What does function mean? What does function mean? Aug 04, 2023 am 10:33 AM

Function means function. It is a reusable code block with specific functions. It is one of the basic components of a program. It can accept input parameters, perform specific operations, and return results. Its purpose is to encapsulate a reusable block of code. code to improve code reusability and maintainability.

Rename files using java's File.renameTo() function Rename files using java's File.renameTo() function Jul 25, 2023 pm 03:45 PM

Use Java's File.renameTo() function to rename files. In Java programming, we often need to rename files. Java provides the File class to handle file operations, and its renameTo() function can easily rename files. This article will introduce how to use Java's File.renameTo() function to rename files and provide corresponding code examples. The File.renameTo() function is a method of the File class.

Use java's File.getParentFile() function to get the parent directory of the file Use java's File.getParentFile() function to get the parent directory of the file Jul 27, 2023 am 11:45 AM

Use java's File.getParentFile() function to get the parent directory of a file. In Java programming, we often need to operate files and folders. When we need to get the parent directory of a file, we can use the File.getParentFile() function provided by Java. This article explains how to use this function and provides code examples. File class in Java is the main class used to operate files and folders. It provides many methods to obtain and manipulate file properties

Use java's File.getParent() function to get the parent path of the file Use java's File.getParent() function to get the parent path of the file Jul 24, 2023 pm 01:40 PM

Use java's File.getParent() function to get the parent path of a file. In Java programming, we often need to operate files and folders. Sometimes, we need to get the parent path of a file, which is the path of the folder where the file is located. Java's File class provides the getParent() method to obtain the parent path of a file or folder. The File class is Java's abstract representation of files and folders. It provides a series of methods for operating files and folders. Among them, get

How to delete a file or directory using File.delete() method in Java? How to delete a file or directory using File.delete() method in Java? Nov 18, 2023 am 08:02 AM

How to delete a file or directory using File.delete() method in Java? Overview: In Java, we can delete a file or directory using the delete() method of the File class. This method is used to delete the specified file or directory. However, it should be noted that this method can only delete empty directories or files that are not opened by other programs. If file or directory deletion fails, you can find the specific reason by catching IOException. Step 1: Import related packages First, we need

See all articles