leronj23
asked on
Upload multiple Images from Flash to PHP
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:FileRefer ence, error:Number){
nameA_txt.text += "HTTP error: with " + fileRef.name + ":error #" + error;}
list_obj2.onHTTPError = function(fileRef:FileRefer ence, error:Number){
nameB_txt.text += "HTTP error: with " + fileRef.name + ":error #" + error;}
list_obj3.onHTTPError = function(fileRef:FileRefer ence, error:Number){
nameC_txt.text += "HTTP error: with " + fileRef.name + ":error #" + error;}
list_obj4.onHTTPError = function(fileRef:FileRefer ence, error:Number){
nameD_txt.text += "HTTP error: with " + fileRef.name + ":error #" + error;}
//attach the listener
file_fa.addListener(list_o bj1);
file_fb.addListener(list_o bj2);
file_fc.addListener(list_o bj3);
file_fd.addListener(list_o bj4);
//the event for the browse button
browseA_butn.clickHandler = function(){
file_fa.browse([{descripti on: "JPEGs", extension: "*.JPG;*.jpg"}]);}
browseB_butn.clickHandler = function(){
file_fb.browse([{descripti on: "JPEGs", extension: "*.JPG;*.jpg"}]);}
browseC_butn.clickHandler = function(){
file_fc.browse([{descripti on: "JPEGs", extension: "*.JPG;*.jpg"}]);}
browseD_butn.clickHandler = function(){
file_fd.browse([{descripti on: "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']['na me'];
copyResizeImage($_FILES['F iledata'][ '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($oldNam e);
if ($type == 2) $src = ImageCreateFromJpeg($oldNa me);
if ($type == 3) $src = ImageCreateFromPng($oldNam e);
/* Convert to JPEG */
$dst = ImageCreateTrueColor($newW idth, $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,ad dress,city ,states,zi pcode,cont act,phone, fax,email, price,mess ages,pictu reA,pictur eB,picture C,pictureD ) VALUES(NOW(),'$topic','$co mpanyname' ,'$address ','$city', '$states', '$zipcode' ,'$contact ','$phone' ,'$fax','$ email','$p rice','$me ssages','$ pictureA', '$pictureB ','$pictur eC','$pict ureD')";
$result = @mysql_query($sql);
?>
i need to be able to make the uploaded images separate to place them in pictureA, pictureB, pictureC, pictureD.
$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:FileRefer
nameA_txt.text += "HTTP error: with " + fileRef.name + ":error #" + error;}
list_obj2.onHTTPError = function(fileRef:FileRefer
nameB_txt.text += "HTTP error: with " + fileRef.name + ":error #" + error;}
list_obj3.onHTTPError = function(fileRef:FileRefer
nameC_txt.text += "HTTP error: with " + fileRef.name + ":error #" + error;}
list_obj4.onHTTPError = function(fileRef:FileRefer
nameD_txt.text += "HTTP error: with " + fileRef.name + ":error #" + error;}
//attach the listener
file_fa.addListener(list_o
file_fb.addListener(list_o
file_fc.addListener(list_o
file_fd.addListener(list_o
//the event for the browse button
browseA_butn.clickHandler = function(){
file_fa.browse([{descripti
browseB_butn.clickHandler = function(){
file_fb.browse([{descripti
browseC_butn.clickHandler = function(){
file_fc.browse([{descripti
browseD_butn.clickHandler = function(){
file_fd.browse([{descripti
//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']['na
copyResizeImage($_FILES['F
$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($oldNam
if ($type == 2) $src = ImageCreateFromJpeg($oldNa
if ($type == 3) $src = ImageCreateFromPng($oldNam
/* Convert to JPEG */
$dst = ImageCreateTrueColor($newW
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,ad
$result = @mysql_query($sql);
?>
i need to be able to make the uploaded images separate to place them in pictureA, pictureB, pictureC, pictureD.
ASKER
I understand what your are saying, but i need the image path to be place in "pictureA,pictureB,picture C,pictureD " so it can be downloaded to my sql database.
Ah. You are uploading 4 images but using 1 connection per image rather than multiple images in 1 connection.
So, you will need to add a POST variable indicating which image it is.
So ...
<?php
if (isset($_POST['image_name' ]) && is_uploaded(...) and move_uploaded_file(..., '/final/destination/for/up loaded/ima ge/' . $_POST['image_name']))
{
// Image is now in the right place.
}
?>
So, you will need to add a POST variable indicating which image it is.
So ...
<?php
if (isset($_POST['image_name'
{
// Image is now in the right place.
}
?>
Or set the name of the image in the ...
If this was HTML then ...
<input type="file" name="PictureA">
<input type="file" name="PictureB">
<input type="file" name="PictureC">
<input type="file" name="PictureD">
and ...
<?php
foreach($_FILES as $s_Picture_x => $a_Uploaded_file)
{
if (is_uploaded($a_Uploaded_f ile['tmp_n ame']) && move_uploaded_file($a_Uplo aded_file[ 'tmp_name' ], '/final/' . $s_Picture_x))
{
// Picture_x is now set based upon the name of the image you used in the <input> tag (or your Flash equivalent).
}
}
If this was HTML then ...
<input type="file" name="PictureA">
<input type="file" name="PictureB">
<input type="file" name="PictureC">
<input type="file" name="PictureD">
and ...
<?php
foreach($_FILES as $s_Picture_x => $a_Uploaded_file)
{
if (is_uploaded($a_Uploaded_f
{
// Picture_x is now set based upon the name of the image you used in the <input> tag (or your Flash equivalent).
}
}
ASKER
here is what going on. in flash i have 4 seperate upload fields. when you hit the upload botton this is how there are sent
file_fa.upload("upload.php "); // pictureA
file_fb.upload("upload.php "); // pictureB
file_fc.upload("upload.php "); // pictureC
file_fd.upload("upload.php "); // pictureD
Now i need "File_fa" to = "pictureA" in my "upload.php" and so on.
Do you think i need 4 seperate PHPs to do this?
file_fa.upload("upload.php
file_fb.upload("upload.php
file_fc.upload("upload.php
file_fd.upload("upload.php
Now i need "File_fa" to = "pictureA" in my "upload.php" and so on.
Do you think i need 4 seperate PHPs to do this?
I don't know flash, but can you show me the properties for file_fa? Is there a name? PHP is getting Filedata as the name. If this was PictureX then that would be OK.
Alternatively ...
file_fa.upload("upload.php ?id=A"); // pictureA
file_fb.upload("upload.php ?id=B"); // pictureB
file_fc.upload("upload.php ?id=C"); // pictureC
file_fd.upload("upload.php ?id=D"); // pictureD
Now, in PHP ...
<?php
if (isset($_GET['id']) && in_array($_GET['id'], array('A', 'B', 'C', 'D')))
{
// Save the file ...
if (is_uploaded_file(...) & move_uploaded_file(..., "/destination/picture{$_GE T['id']}") )
{
// All moved and named.
}
else
{
// Couldn't save.
}
}
else
{
// No id for picture.
}
Alternatively ...
file_fa.upload("upload.php
file_fb.upload("upload.php
file_fc.upload("upload.php
file_fd.upload("upload.php
Now, in PHP ...
<?php
if (isset($_GET['id']) && in_array($_GET['id'], array('A', 'B', 'C', 'D')))
{
// Save the file ...
if (is_uploaded_file(...) & move_uploaded_file(..., "/destination/picture{$_GE
{
// All moved and named.
}
else
{
// Couldn't save.
}
}
else
{
// No id for picture.
}
ASKER
this just might work.
what do "....." in the above code mean. im not to familiar with PHP.
basicly "file_fa" and so on are the variable that are sent to PHP the be converted to images and the path way.
what do "....." in the above code mean. im not to familiar with PHP.
basicly "file_fa" and so on are the variable that are sent to PHP the be converted to images and the path way.
... as in put in the bits here that have already been mentioned.
file_fa looks like an object. Objects have properties. What properties does this object have? Does it have a name? If so is the name currently Filedata?
If so, change the name to the required one.
file_fa looks like an object. Objects have properties. What properties does this object have? Does it have a name? If so is the name currently Filedata?
If so, change the name to the required one.
ASKER
Is this how i would put what you showed me with my above php code. the php code i use resizes the image to a specific size. if not can you make the neccessary changes. im sorry to be a pest. you are a great help.
<?php
$a= "files";
if (isset($_GET['id']) && in_array($_GET['id'], array('A', 'B', 'C', 'D')))
{
// Save the file ...
if (is_uploaded_file($_FILES[ 'Filedata' ]['name']) & copyResizeImage($_FILES['F iledata'][ 'tmp_name' ], "/$a/picture{$_GET['id']}" ))
{ // All moved and named. }
else { // Couldn't save. } }
else { // No id for picture. }
$d= chmod($pictureA,0777);
$d= chmod($pictureB,0777);
$d= chmod($pictureC,0777);
$d= chmod($pictureD,0777);
---------EVERYTHING BELOW HERE WORKS FINE--------------------
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($oldNam e);
if ($type == 2) $src = ImageCreateFromJpeg($oldNa me);
if ($type == 3) $src = ImageCreateFromPng($oldNam e);
/* Convert to JPEG */
$dst = ImageCreateTrueColor($newW idth, $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,ad dress,city ,states,zi pcode,cont act,phone, fax,email, price,mess ages,pictu reA,pictur eB,picture C,pictureD ) VALUES(NOW(),'$topic','$co mpanyname' ,'$address ','$city', '$states', '$zipcode' ,'$contact ','$phone' ,'$fax','$ email','$p rice','$me ssages','$ pictureA', '$pictureB ','$pictur eC','$pict ureD')";
$result = @mysql_query($sql);
?>
<?php
$a= "files";
if (isset($_GET['id']) && in_array($_GET['id'], array('A', 'B', 'C', 'D')))
{
// Save the file ...
if (is_uploaded_file($_FILES[
{ // All moved and named. }
else { // Couldn't save. } }
else { // No id for picture. }
$d= chmod($pictureA,0777);
$d= chmod($pictureB,0777);
$d= chmod($pictureC,0777);
$d= chmod($pictureD,0777);
---------EVERYTHING BELOW HERE WORKS FINE--------------------
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($oldNam
if ($type == 2) $src = ImageCreateFromJpeg($oldNa
if ($type == 3) $src = ImageCreateFromPng($oldNam
/* Convert to JPEG */
$dst = ImageCreateTrueColor($newW
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,ad
$result = @mysql_query($sql);
?>
Ah! I see.
NO!!!!!!
You are issuing 4 separate and unrelated requests.
file_fa.upload("upload.php "); // pictureA
file_fb.upload("upload.php "); // pictureB
file_fc.upload("upload.php "); // pictureC
file_fd.upload("upload.php "); // pictureD
is 4 uploads, each upload will have 1 picture. The script will know NOTHING about the other 3 images. You will need to process each image separately.
Unless you can upload the 4 images in 1 request.
I've no idea if you can do that with Flash. You can with HTML.
If your PHP generated some plain text output (debugging info), can you see that in your flash?
Say something like ...
response_a = file_fa.upload("upload.php ");
print response_a;
NO!!!!!!
You are issuing 4 separate and unrelated requests.
file_fa.upload("upload.php
file_fb.upload("upload.php
file_fc.upload("upload.php
file_fd.upload("upload.php
is 4 uploads, each upload will have 1 picture. The script will know NOTHING about the other 3 images. You will need to process each image separately.
Unless you can upload the 4 images in 1 request.
I've no idea if you can do that with Flash. You can with HTML.
If your PHP generated some plain text output (debugging info), can you see that in your flash?
Say something like ...
response_a = file_fa.upload("upload.php
print response_a;
By tagging each request with the image, you can use that to populate the picture manually.
ASKER
file_fa.upload("upload.php ?id=A"); // pictureA
file_fb.upload("upload.php ?id=B"); // pictureB
file_fc.upload("upload.php ?id=C"); // pictureC
file_fd.upload("upload.php ?id=D"); // pictureD
wouldnt this work since im using the same PHP file and when it uploads its using the "id= A" and so on to seperate each image in the php.
file_fb.upload("upload.php
file_fc.upload("upload.php
file_fd.upload("upload.php
wouldnt this work since im using the same PHP file and when it uploads its using the "id= A" and so on to seperate each image in the php.
Are you thinking that SOMEHOW upload.php will wait until it gets 4 pictures before it process ANY of them?
Each upload from Flash (the client) will send ONE picture to the PHP script upload AND tag the script with a URL parameter indicating the image.
ONE PICTURE!!!!!!!
Not 2, 3 or 4.
ONE!!!!
So the first time upload.php runs it will get image 1 with a param of id=A.
The next line is for the second image and will have a parameter of id=B
etc.
upload.php will run 4 times.
Each time 1 picture with 1 parameter.
The PHP script WILL KNOW NOTHING ABOUT THE OTHER 3 IMAGES!!!!
Imagine a html form. Each of your file_fx's is a form. 4 forms on 1 page with the same action is still 4 forms. Just because you fill in four forms,only 1 is submitted when you click the submit button.
You either have to store one picture at a time.
OR
combine all 4 images into a SINGLE call to upload.php like you would do if you were using HTML
<form enctype="multipart/form-da ta" action="upload.php" method="POST">
Image 1<input name="Image[1]" type="file" />
Image 2<input name="Image[2]" type="file" />
Image 3<input name="Image[3]" type="file" />
Image 4<input name="Image[4]" type="file" />
<input type="submit" value="Send File" />
</form>
The $_FILES array for this form would be ...
array (
'Image' =>
array (
'name' =>
array (
1 => 'raq1.psp',
2 => 'System.pas',
3 => 'filter_files.php',
4 => 'bad.txt',
),
'type' =>
array (
1 => 'application/octet-stream' ,
2 => 'application/octet-stream' ,
3 => 'application/octet-stream' ,
4 => 'text/plain',
),
'tmp_name' =>
array (
1 => 'D:\\Data\\PHP\\File Uploads\\php924.tmp',
2 => 'D:\\Data\\PHP\\File Uploads\\php925.tmp',
3 => 'D:\\Data\\PHP\\File Uploads\\php926.tmp',
4 => 'D:\\Data\\PHP\\File Uploads\\php927.tmp',
),
'error' =>
array (
1 => 0,
2 => 0,
3 => 0,
4 => 0,
),
'size' =>
array (
1 => 5569,
2 => 491852,
3 => 16874,
4 => 937160,
),
),
)
If the form was ...
<form enctype="multipart/form-da ta" action="upload.php" method="POST">
Image 1<input name="picture_a" type="file" />
Image 2<input name="picture_b" type="file" />
Image 3<input name="picture_c" type="file" />
Image 4<input name="picture_d" type="file" />
<input type="submit" value="Send File" />
</form>
then $_FILES would be ...
array (
'picture_a' =>
array (
'name' => 'System.pas',
'type' => 'application/octet-stream' ,
'tmp_name' => 'D:\\Data\\PHP\\File Uploads\\php92E.tmp',
'error' => 0,
'size' => 491852,
),
'picture_b' =>
array (
'name' => 'raq1.psp',
'type' => 'application/octet-stream' ,
'tmp_name' => 'D:\\Data\\PHP\\File Uploads\\php92F.tmp',
'error' => 0,
'size' => 5569,
),
'picture_c' =>
array (
'name' => 'filter_files.php',
'type' => 'application/octet-stream' ,
'tmp_name' => 'D:\\Data\\PHP\\File Uploads\\php930.tmp',
'error' => 0,
'size' => 16874,
),
'picture_d' =>
array (
'name' => 'bad.txt',
'type' => 'text/plain',
'tmp_name' => 'D:\\Data\\PHP\\File Uploads\\php931.tmp',
'error' => 0,
'size' => 937160,
),
)
Either upload an array of files - in which case the name, type, tmp_name, error and size will be an array - or use different names in which case the $_FILES[key] will be the input tag's name.
Each upload from Flash (the client) will send ONE picture to the PHP script upload AND tag the script with a URL parameter indicating the image.
ONE PICTURE!!!!!!!
Not 2, 3 or 4.
ONE!!!!
So the first time upload.php runs it will get image 1 with a param of id=A.
The next line is for the second image and will have a parameter of id=B
etc.
upload.php will run 4 times.
Each time 1 picture with 1 parameter.
The PHP script WILL KNOW NOTHING ABOUT THE OTHER 3 IMAGES!!!!
Imagine a html form. Each of your file_fx's is a form. 4 forms on 1 page with the same action is still 4 forms. Just because you fill in four forms,only 1 is submitted when you click the submit button.
You either have to store one picture at a time.
OR
combine all 4 images into a SINGLE call to upload.php like you would do if you were using HTML
<form enctype="multipart/form-da
Image 1<input name="Image[1]" type="file" />
Image 2<input name="Image[2]" type="file" />
Image 3<input name="Image[3]" type="file" />
Image 4<input name="Image[4]" type="file" />
<input type="submit" value="Send File" />
</form>
The $_FILES array for this form would be ...
array (
'Image' =>
array (
'name' =>
array (
1 => 'raq1.psp',
2 => 'System.pas',
3 => 'filter_files.php',
4 => 'bad.txt',
),
'type' =>
array (
1 => 'application/octet-stream'
2 => 'application/octet-stream'
3 => 'application/octet-stream'
4 => 'text/plain',
),
'tmp_name' =>
array (
1 => 'D:\\Data\\PHP\\File Uploads\\php924.tmp',
2 => 'D:\\Data\\PHP\\File Uploads\\php925.tmp',
3 => 'D:\\Data\\PHP\\File Uploads\\php926.tmp',
4 => 'D:\\Data\\PHP\\File Uploads\\php927.tmp',
),
'error' =>
array (
1 => 0,
2 => 0,
3 => 0,
4 => 0,
),
'size' =>
array (
1 => 5569,
2 => 491852,
3 => 16874,
4 => 937160,
),
),
)
If the form was ...
<form enctype="multipart/form-da
Image 1<input name="picture_a" type="file" />
Image 2<input name="picture_b" type="file" />
Image 3<input name="picture_c" type="file" />
Image 4<input name="picture_d" type="file" />
<input type="submit" value="Send File" />
</form>
then $_FILES would be ...
array (
'picture_a' =>
array (
'name' => 'System.pas',
'type' => 'application/octet-stream'
'tmp_name' => 'D:\\Data\\PHP\\File Uploads\\php92E.tmp',
'error' => 0,
'size' => 491852,
),
'picture_b' =>
array (
'name' => 'raq1.psp',
'type' => 'application/octet-stream'
'tmp_name' => 'D:\\Data\\PHP\\File Uploads\\php92F.tmp',
'error' => 0,
'size' => 5569,
),
'picture_c' =>
array (
'name' => 'filter_files.php',
'type' => 'application/octet-stream'
'tmp_name' => 'D:\\Data\\PHP\\File Uploads\\php930.tmp',
'error' => 0,
'size' => 16874,
),
'picture_d' =>
array (
'name' => 'bad.txt',
'type' => 'text/plain',
'tmp_name' => 'D:\\Data\\PHP\\File Uploads\\php931.tmp',
'error' => 0,
'size' => 937160,
),
)
Either upload an array of files - in which case the name, type, tmp_name, error and size will be an array - or use different names in which case the $_FILES[key] will be the input tag's name.
This way, you get all 4 pictures to upload.php in 1 go and can process them all at the same time.
ASKER
Can i do this?
<? php
$a = "/file/";
If (id = A)
{pictureA = $a.$_FILES['Filedata']['na me'];
copyResizeImage($_FILES['F iledata'][ 'tmp_name' ],$picture A);
$d= chmod($pictureA,0777);}
else if (id = B)
{pictureB = $a.$_FILES['Filedata']['na me'];
copyResizeImage($_FILES['F iledata'][ 'tmp_name' ],$picture B);
$d= chmod($pictureB,0777);}
else if (id = C)
{pictureC = $a.$_FILES['Filedata']['na me'];
copyResizeImage($_FILES['F iledata'][ 'tmp_name' ],$picture C);
$d= chmod($pictureC,0777);}
else if (id = D)
{pictureD = $a.$_FILES['Filedata']['na me'];
copyResizeImage($_FILES['F iledata'][ 'tmp_name' ],$picture D);
$d= chmod($pictureD,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($oldNam e);
if ($type == 2) $src = ImageCreateFromJpeg($oldNa me);
if ($type == 3) $src = ImageCreateFromPng($oldNam e);
/* Convert to JPEG */
$dst = ImageCreateTrueColor($newW idth, $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,ad dress,city ,states,zi pcode,cont act,phone, fax,email, price,mess ages,pictu reA,pictur eB,picture C,pictureD ) VALUES(NOW(),'$topic','$co mpanyname' ,'$address ','$city', '$states', '$zipcode' ,'$contact ','$phone' ,'$fax','$ email','$p rice','$me ssages','$ pictureA', '$pictureB ','$pictur eC','$pict ureD')";
$result = @mysql_query($sql);
?>
<? php
$a = "/file/";
If (id = A)
{pictureA = $a.$_FILES['Filedata']['na
copyResizeImage($_FILES['F
$d= chmod($pictureA,0777);}
else if (id = B)
{pictureB = $a.$_FILES['Filedata']['na
copyResizeImage($_FILES['F
$d= chmod($pictureB,0777);}
else if (id = C)
{pictureC = $a.$_FILES['Filedata']['na
copyResizeImage($_FILES['F
$d= chmod($pictureC,0777);}
else if (id = D)
{pictureD = $a.$_FILES['Filedata']['na
copyResizeImage($_FILES['F
$d= chmod($pictureD,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($oldNam
if ($type == 2) $src = ImageCreateFromJpeg($oldNa
if ($type == 3) $src = ImageCreateFromPng($oldNam
/* Convert to JPEG */
$dst = ImageCreateTrueColor($newW
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,ad
$result = @mysql_query($sql);
?>
ASKER
disregard the last posting. i see what you are say. i have to have all the picutures be able to be uploaded at one time from flash to work in php the way im trying to do it.
ASKER
is there anyway i can call for the id number that i have automaticly incrementing in sql to populate in php. so when i do load image 2, 3 , and 4 i can refer to that number and just update and load the pictures in to that specific line. i might have 10000 people so when a new person comes along i can make sure their picture show up in their row of information.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yep. As bonmat86 says.
I think you have all the info you need.
I think you have all the info you need.
WOW! Not even a split or a thanks! Gee.
ASKER
something happen with my computer how do you split the points?
Too late now!!!!
Ha!
If you really want to, go to Community Support and ask a 0pt question asking for the points to be reassigned or to have the PAQ removed back so you can allocate the points yourself.
Ha!
If you really want to, go to Community Support and ask a 0pt question asking for the points to be reassigned or to have the PAQ removed back so you can allocate the points yourself.
ASKER
i'll do that. thanks for your help
Instead, move the uploaded files ...
if (is_uploaded_file($_FILES[
{
// You can now use the file that exists in '/uploaded/file_destinatio
}