Flash upload File

Source: Internet
Author: User
Tags new features
Upload has been trying to do this function, think a lot of crooked, not fruit!
Yesterday suddenly on the Blueidea to see the new features of Flash 8 (although it has been installed on the Flash 8 but has not been carefully studied, really ashamed:p) introduced Flash 8 provides upload and download interface, immediately went down to study, really good. Although the upload still needs background script support, but also enough for my beautiful for a while:D
Here are the results of the research, do not dare to enjoy alone, out of the show:D
Uploadfile.fla

CODE:
Load Package
Import flash.net.FileReference;
Define actor Filereference Object
var fileref:filereference = new Filereference ();
Defining Listener Objects
var filelsn:object = new Object ();
Defines the parameters of the Browse method for a file type array Filereference object
Description: Description
Extension: List of extended names
var filetyp:array = new Array ({description: "Image files", extension: "*.jpg;*.gif"}, {description: "Document files", Extension: "*.txt;*.doc"});
Btnbrowse.onrelease = function () {
Open the Select File dialog box
Fileref.browse (Filetyp);
};
Btnupload.onrelease = function () {
Start uploading
Fileref.upload ("uploadfile.php");
};
Btnclear.onrelease = function () {
Strstate.text = "";
};
Select File Event
Filelsn.onselect = function (file:filereference) {
Strstate.text + = "Onselect '" +file.name+ "' \ n";
};
Cancel Selection
Filelsn.oncancel = function (file:filereference) {
Strstate.text + = "cancel!\n";
};
Open File Start upload
Filelsn.onopen = function (file:filereference) {
Strstate.text = "Uploading ... "+file.name+" ' \ n ';
};
Upload successful
Filelsn.oncomplete = function (file:filereference) {
Strstate.text + = "File" "+file.name+" ' Upload successfull!\n ';
};
Upload process
filelsn.onprogress = function (File:filereference, Bytesloaded:number, Bytestotal:number): Void {
Strstate.text + = "OnProgress:" +file.name+ "with bytesloaded:" +bytesloaded+ "bytestotal:" +bytestotal+ "\ n";
};
HTTP Error
Filelsn.onhttperror = function (File:filereference, httperror:number) {
Strstate.text + = "HTTP ERROR:" +httperror+ "\ n";
};
IO Error
Filelsn.onioerror = function (file:filereference): Void {
Strstate.text + = "IO Error:" +file.name+ "\ n";
};
Security error
Filelsn.onsecurityerror = function (File:filereference, errorstring:string): Void {
Strstate.text + = "Onsecurityerror:" +file.name+ "errorstring:" +errorstring;
};
Binding listeners
Fileref.addlistener (FILELSN);
Other properties or events refer to the section on the Filereference object in Help


uploadfile.php

CODE:
<?php
The file Form Name property passed by Flash is Filedata
$fileName = $_files["Filedata"] ["name"];
$file = $_files["Filedata"] ["tmp_name"];
$path = "uploadfiles/";
if (Move_uploaded_file ($file, $path. $fileName)) {
Echo 1;
}else{
echo 0;
}
/*
* As long as the upload code is enough
* Flash does not seem to judge the return value of the file
* Even if the file report wrong Flash can not be analyzed
* So it's best to make sure this file doesn't go wrong
*/
?>
source File Download



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.