Click here to Skip to main content
13,505,095 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 30 Jan 2010

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.


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.


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 = 

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

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

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(""+
          albumHash+"&user="+_root.userId)) {
    errorList.push("Failed to upload : ";}

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"?>
    <album><id>1</id><name>My Little Baby</name></album>
    <album><id>2</id><name>Wedding Photos</name></album>
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;
//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.


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


About the Author

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.

You may also be interested in...

Comments and Discussions

GeneralHttp Headers Pin
chris fahey1-Feb-10 14:15
memberchris fahey1-Feb-10 14:15 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180417.1 | Last Updated 30 Jan 2010
Article Copyright 2010 by aneesme
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid