Home » Flash & Action Script, PHP/MySQL » Batch Uploader using Flash Action Script 2


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 the site users to upload photos from their computer to their online account. This flash tool with the complete source code is given 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.

The photos were organized in Albums. The users could create albums in their Photo manage page. To give the users the ability to upload a bunch of photos together as a batch process, the tool was introduced. User can launch this Batch uploader tool from their account homepage and browse for Photos from their folders. The features of this uploader include the ability to add files from different folders to the list. The file list can be managed by removing selected files or adding more files in to the list. When the user is ready with the list of files, he/she can then choose an Album fro m the dropdown where these photos will be stored.

The Batch Uploader is 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.

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 request for the 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";

The 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” movieclip 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 add a record in the database. The ID of the album the user has chosen from the list and the user Id 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.

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 source file in CS3 format.Free Batch Upload tool – Flash Action Script

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.


  1. Alex says:

    Thanks for posting this article. It really helped a lot.


  2. marko says:

    Good tutorial, but the flash doesn’t work… what is the xml file name? for the php “albumList.php” it’s correct?

    thank you so much!


Leave a Reply

Page optimized by WP Minify WordPress Plugin