Click here to Skip to main content
Click here to Skip to main content
Go to top

Batch Uploader Using Flash Action Script 2 or Multiple File Upload Using Flash

, 30 Jan 2010
Rate this:
Please Sign up or sign in to vote.
The Batch Uploader was developed using Action Script 2, and uses PHP as the backend to process the file upload.

Introduction

The Batch Uploader was developed using Action Script 2 and uses PHP as the backend to process the file upload. The current user ID can be passed to the Flash module by defining a FlashVars variable as "userid", which will be passed to the PHP function when albums are requested or when the upload is processed.

Background

Pretty long time back, I developed a batch uploading tool in Flash for a large online photo sharing website. The purpose of the tool was to allow site users to upload photos from their computer to their online account. This Flash tool with the complete source code is available for free here.

Many of the batch process tools available cause errors while processing for a long time, and the browsers try to abort the script by showing a warning alert to the user. I was successful in fixing this issue.

Using the code

Here is an example of passing a variable to Flash from HTML using FlashVars:

//Object Tag Example:
<PARAM NAME=FlashVars VALUE="userid=10">
//Embed Tag Example:
<EMBED href="display.swf" FlashVars="userid=10"></EMBED>

The application initially requests for albums created by the user, by calling a PHP script which returns a list of albums and their IDs in XML format.

See the code at line 86.

var albumListURL = 
  (_root.albumUrl)?_root.albumUrl:"http://yourwebsite.com/albumList.php";

albumList.php should return the list of albums in XML format, as shown below:

<?xml version="1.0" encoding="utf-8"?>
<albums>
    <album><id>1</id><name>My Little Baby</name></album>
    <album><id>2</id><name>Wedding Photos</name></album>
</albums>

The tool also allows the user to create a new album right from the uploader interface. Open the "albumpop_mc" movie clip on the stage to see the album creation functionalities.

The batch upload tool sends selected files one by one to the server. uploadItem (line number 172) is the function which sends the file to the server PHP script.

if (!itemRef.upload("http://yourwebsite.com/batchUploadProcess.php&album="+
          albumHash+"&user="+_root.userId)) {
    errorList.push("Failed to upload : "+item.name);}

This code sends one file at a time to a PHP script named "batchUploadProcess.php" which receives the file at the server and adds a record in the database. The ID of the album the user has chosen from the list and the user IDd the application is given as a FlashVars variable are sent to the PHP script.

Below is the script I used to process the file sent from Flash:

<?xml version="1.0" encoding="utf-8"?>
<albums>
    <album><id>1</id><name>My Little Baby</name></album>
    <album><id>2</id><name>Wedding Photos</name></album>
</albums>
switch($_FILES['Filedata']['error']) {
    case 1:
    case 2:
    case 3:
    case 6: die; break;
    case 4:
    case 0: break;
    default: die; break;
}
if ($_FILES['Filedata']['error'] == 0) {
    $fileInfo['photo'] = getimagesize($_FILES['Filedata']['tmp_name']);
    if ($fileInfo['photo'][2] != 2) die;
}
move_uploaded_file($_FILES['Filedata']['tmp_name'], 
                   "./photos/originals/YourFileName.jpg");
//Add your other codes here
echo "success";

Click the below link to download the latest source file in CS3 format:

If you are an intermediate Flash programmer, you can easily understand the code flow. Modify and use the code wherever you want. I don't really want to explain the complete code here. But you can contact me if you have any questions.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

aneesme
Architect Amoeba Solution Kiosk
India India
Anees Madathil, having more than 5 years of experiencing in ideating, designing, developing web applications and rich internet applications now serves as a Solution Analyst at Amoeba Solution Kiosk and writes articles and tutorials on almost all web related tools and languages.
 
Amoeba! an innovative Idea House based in Bangalore provides solutions in Web, Software & Media world. The ASK (Amoeba Solution Kiosk) community founded by Amoeba enables and encourages various technology discussions across beginners, experts & the geeks of the Web World.
 
Developers can download program modules, source codes, solved problems and can ask questions on various technologies.

Comments and Discussions

 
GeneralHttp Headers Pinmemberchris fahey1-Feb-10 14:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 30 Jan 2010
Article Copyright 2010 by aneesme
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid