Solved

Upload multiple Images from Flash to PHP

Posted on 2006-06-15
8
1,574 Views
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
import flash.net.FileReference;

//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 = file_fa.name;}
list_obj2.onSelect = function(){
      upload_butn.enabled = true;      
      nameB_txt.text = file_fb.name;}
list_obj3.onSelect = function(){
      upload_butn.enabled = true;
      nameC_txt.text = file_fc.name;}
list_obj4.onSelect = function(){
      upload_butn.enabled = true;
      nameD_txt.text = file_fd.name;}

list_obj1.onComplete = function(){
      nameA_txt.text = "All Done";
            rec_mc.clear();
      upload_butn.enabled = false;}
list_obj2.onComplete = function(){
      nameB_txt.text = "All Done";
            rec_mc.clear();
      upload_butn.enabled = false;}
list_obj3.onComplete = function(){
      nameC_txt.text = "All Done";
            rec_mc.clear();
      upload_butn.enabled = false;}
list_obj4.onComplete = function(){
      nameD_txt.text = "All Done";
      rec_mc.clear();
      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;
      drawRec(percent);
}
//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 " + fileRef.name;}
list_obj2.onIOError = function(fileRef){
      nameB_txt.text = "IO error with " + fileRef.name;}
list_obj3.onIOError = function(fileRef){
      nameC_txt.text = "IO error with " + fileRef.name;}
list_obj4.onIOError = function(fileRef){
      nameD_txt.text = "IO error with " + fileRef.name;}

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

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


//attach the listener
file_fa.addListener(list_obj1);
file_fb.addListener(list_obj2);
file_fc.addListener(list_obj3);
file_fd.addListener(list_obj4);

//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(){
      file_fa.upload("upload.php");
      file_fb.upload("upload.php");
      file_fc.upload("upload.php");
      file_fd.upload("upload.php");
      }

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

<?php

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

copyResizeImage($_FILES['Filedata']['tmp_name'],$b);

$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);

?>
0
Comment
Question by:leronj23
8 Comments
 
LVL 4

Expert Comment

by:Guic
ID: 16913428
Hi,

$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')";

Rgds
0
 

Author Comment

by:leronj23
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.
0
 

Author Comment

by:leronj23
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.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:mattjp88
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?

-Matt
0
 

Author Comment

by:leronj23
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.
0
 

Author Comment

by:leronj23
ID: 16931069
if you can help with this:

http://www.experts-exchange.com/Web/Q_21890586.html

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

Accepted Solution

by:
Roonaan earned 500 total points
ID: 16931767
leronj23,

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.

-r-
0
 
LVL 6

Expert Comment

by:mattjp88
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. http://www.google.com/search?q=flash+file+upload

-Matt
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

821 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