Upload multiple Images from Flash to PHP

Posted on 2006-06-15
Last Modified: 2008-01-09
I need Help Fast. The Problem that im having is that i want people to upload 4 images in Flash 8 at the same time and those image's "PATH" be sent to PHP and place into "PictureA,  PictureB, PictureC, PictureD". The Flash upload works fine for 4 images. The PHP works fine for one image. The image path shows up in sql and the image is placed into my server.

$b = the name of the path that will be save to sql, but i need it to be "PictureA,  PictureB, PictureC, PictureD".

Please Help 500 points and a Grade A

-----------------Flash 8 Actionscript---------------

//import the FileReference Object

//initial settings
upload_butn.enabled = false;

//the fileReference object
var file_fa:FileReference = new FileReference();
var file_fb:FileReference = new FileReference();
var file_fc:FileReference = new FileReference();
var file_fd:FileReference = new FileReference();

//object for listening to for FileReference events
var list_obj1:Object = new Object();
var list_obj2:Object = new Object();
var list_obj3:Object = new Object();
var list_obj4:Object = new Object();

list_obj1.onSelect = function(){
      upload_butn.enabled = true;
      nameA_txt.text =;}
list_obj2.onSelect = function(){
      upload_butn.enabled = true;      
      nameB_txt.text =;}
list_obj3.onSelect = function(){
      upload_butn.enabled = true;
      nameC_txt.text =;}
list_obj4.onSelect = function(){
      upload_butn.enabled = true;
      nameD_txt.text =;}

list_obj1.onComplete = function(){
      nameA_txt.text = "All Done";
      upload_butn.enabled = false;}
list_obj2.onComplete = function(){
      nameB_txt.text = "All Done";
      upload_butn.enabled = false;}
list_obj3.onComplete = function(){
      nameC_txt.text = "All Done";
      upload_butn.enabled = false;}
list_obj4.onComplete = function(){
      nameD_txt.text = "All Done";
      upload_butn.enabled = false;}

list_obj1.onProgress = function (bytesTotal, bytesLoaded){
      var percent = bytesLoaded/file_fa.size;
      var percent = bytesLoaded/file_fb.size;
      var percent = bytesLoaded/file_fc.size;
      var percent = bytesLoaded/file_fd.size;
//if a user selects cancel
list_obj1.onCancel = function(){
      nameA_txt.text = "Cancel was selected";}
list_obj2.onCancel = function(){
      nameB_txt.text = "Cancel was selected";}
list_obj3.onCancel = function(){
      nameC_txt.text = "Cancel was selected";}
list_obj4.onCancel = function(){
      nameD_txt.text = "Cancel was selected";}

//if there is an IO error
list_obj1.onIOError = function(fileRef){
      nameA_txt.text = "IO error with " +;}
list_obj2.onIOError = function(fileRef){
      nameB_txt.text = "IO error with " +;}
list_obj3.onIOError = function(fileRef){
      nameC_txt.text = "IO error with " +;}
list_obj4.onIOError = function(fileRef){
      nameD_txt.text = "IO error with " +;}

//security error problem
list_obj1.onSecurityError = function(fileRef, error){
      nameA_txt.text = "Security error with " + + ":" + error;}
list_obj2.onSecurityError = function(fileRef, error){
      nameB_txt.text = "Security error with " + + ":" + error;}
list_obj3.onSecurityError = function(fileRef, error){
      nameC_txt.text = "Security error with " + + ":" + error;}
list_obj4.onSecurityError = function(fileRef, error){
      nameD_txt.text = "Security error with " + + ":" + error;}

list_obj1.onHTTPError = function(fileRef:FileReference, error:Number){
      nameA_txt.text += "HTTP error: with " + + ":error #" + error;}
list_obj2.onHTTPError = function(fileRef:FileReference, error:Number){
      nameB_txt.text += "HTTP error: with " + + ":error #" + error;}
list_obj3.onHTTPError = function(fileRef:FileReference, error:Number){
      nameC_txt.text += "HTTP error: with " + + ":error #" + error;}
list_obj4.onHTTPError = function(fileRef:FileReference, error:Number){
      nameD_txt.text += "HTTP error: with " + + ":error #" + error;}

//attach the listener

//the event for the browse button
browseA_butn.clickHandler = function(){
      file_fa.browse([{description: "JPEGs", extension: "*.JPG;*.jpg"}]);}
browseB_butn.clickHandler = function(){
      file_fb.browse([{description: "JPEGs", extension: "*.JPG;*.jpg"}]);}
browseC_butn.clickHandler = function(){
      file_fc.browse([{description: "JPEGs", extension: "*.JPG;*.jpg"}]);}
browseD_butn.clickHandler = function(){
      file_fd.browse([{description: "JPEGs", extension: "*.JPG;*.jpg"}]);      }

//the event for the upload button
upload_butn.clickHandler = function(){

-------------------PHP that i Use-------------------------------------------


$a= "/files/";
$b= $a.$_FILES['Filedata']['name'];


$d= chmod($b,0777);
function copyResizeImage($oldName, $newName, $maxWidth = 365, $maxHeight = 365)
    if (!is_file($oldName)) return false; /* No input */
    if (is_file($newName)) return false; /* Output exists */
    if ($maxWidth <= 0 || $maxHeight <= 0) return false; /* invalid size */
    list($oldWidth, $oldHeight, $type, $attr) = getimagesize($oldName);
    if ($type > 3) return false; /* unsupported image type */
    /* Resize if necessary */
    $newWidth = $oldWidth;
    $newHeight = $oldHeight;
    if ($newHeight <> $maxHeight)
        $newWidth = ($newWidth / ($newHeight / $maxHeight));
        $newHeight = $maxHeight;
    if ($newWidth <> $maxWidth)
        $newHeight = ($newHeight / ($newWidth / $maxWidth));
        $newWidth = $maxWidth;
    /* Increase memory limit to support larger files */
    ini_set('memory_limit', '32M');
    /* Read source file */
    if ($type == 1) $src = ImageCreateFromGif($oldName);
    if ($type == 2) $src = ImageCreateFromJpeg($oldName);
    if ($type == 3) $src = ImageCreateFromPng($oldName);
    /* Convert to JPEG */        
    $dst = ImageCreateTrueColor($newWidth, $newHeight);
    ImageCopyResized($dst, $src, 0, 0, 0, 0,
        $newWidth, $newHeight,
        $oldWidth, $oldHeight);
    /* Write destination file */        
    return(imagejpeg($dst, $newName));

DEFINE ('DB_USER', '********');
DEFINE ('DB_PASSWORD', '********');
DEFINE ('DB_HOST', 'mysql');
DEFINE ('DB_NAME', 'temp');
// Make the connnection.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );

$sql = "INSERT INTO test

(date,topic,companyname,address,city,states,zipcode,contact,phone,fax,email,price,messages) VALUES(NOW(),'$topic','$companyname','$address','$city','$states','$zipcode','$contact','$phone','$fax','$email','$price','$messages','$pictureA','$pictureB','$pictureC','$pictureD')";

$result = @mysql_query($sql);

Question by:leronj23

Expert Comment

ID: 16913428

$sql = "INSERT INTO test

(date,topic,companyname,address,city,states,zipcode,contact,phone,fax,email,price,messages,******* miss something here ??******* ) VALUES(NOW(),'$topic','$companyname','$address','$city','$states','$zipcode','$contact','$phone','$fax','$email','$price','$messages','$pictureA','$pictureB','$pictureC','$pictureD')";


Author Comment

ID: 16913447
$sql = "INSERT INTO test

(date,topic,companyname,address,city,states,zipcode,contact,phone,fax,email,price,messages,pictureA,pictureB,pictureC,pictureD) VALUES(NOW(),'$topic','$companyname','$address','$city','$states','$zipcode','$contact','$phone','$fax','$email','$price','$messages','$pictureA','$pictureB','$pictureC','$pictureD')";

sorry i forgot to type that in.
i need to be able to make the uploaded images separate to place them in pictureA, pictureB, pictureC, pictureD.

Author Comment

ID: 16921320
can any one help me. i want to try to combine 4 pictures to one so it can upload them at the same time.
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Expert Comment

ID: 16930993
ok, I am a PHP guy, not Flash, so I am a little lost.  So you have the user choose 4 files in Flash, then they are sent to PHP.  I see that you write the Filenames to a database, but only see the uploading of one picture to your server.  What isn't working in your script?


Author Comment

ID: 16931062
this is how i send the images to PHP:

     file_fa.upload("upload.php");// Picture1
     file_fb.upload("upload.php");// Picture2
     file_fc.upload("upload.php");// Picture3
     file_fd.upload("upload.php");// Picture4

how do you specify a specific file in php when your're doing an upload. Like "file_fa" is for "pictureA" and so on.

Author Comment

ID: 16931069
if you can help with this:

then i want need this tutorial, because then all i have to do is use session variables to update the images in sql
LVL 49

Accepted Solution

Roonaan earned 500 total points
ID: 16931767

You have to be aware that every Flash Actionscript file_fa.upload() .. file_fd.upload() is a single request to the server, rather than one request with four uploads.

You therefor might want to add partnumbers to the php call:

     file_fa.upload("upload.php?part=1");// Picture1
     file_fb.upload("upload.php?part=2");// Picture2
     file_fc.upload("upload.php?part=3");// Picture3
     file_fd.upload("upload.php?part=4");// Picture4

On serverside you now can use $partnum = intval($_GET['part']); to get the part number.


Expert Comment

ID: 16931773
oh, ok.  For PHP to upload a file, you need to send it the file by posting it to that page.  The form must also have a special argument in it.  But that is for HTML.  I am not sure if there is a way to upload a file by passing it via the URL.  I did some checking, and I have not found a way to upload a file via PHP that takes the path to the file as a URL parameter.  All of the scripts I found use the post method in forms.  Sorry, but I believe that is the way browsers need it to work, as a security thing.  

Try a few of these paes, flash seems pretty powerful.  You could maybe upload the file via flash and then call a PHP page with the filename in the URL to resize and such the image.


Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Video sharing with user login 3 205
Accessing Live Dynamic Stream 6 197
Install adobe flash plugin for Firefox win 7 9 70
HTML 5 video and audio or Flash 1 57
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question