Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Upload multiple Images from Flash to PHP

Posted on 2006-06-15
8
Medium Priority
?
1,594 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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…
Suggested Courses

916 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