PDA

View Full Version : Additional variable with File Upload


snapple
01-14-2006, 08:08 PM
Hi,

Is there any way to send additional variables (a name and a comment, for example) along with a file upload using the FileReference class?

Thanks for any help or advice.

Regards, snapple :)

Flash Gordon
01-14-2006, 08:13 PM
2 things:
can you post your code
I don't quite understand what you want to do. Are you wanting to store that info in database?

snapple
01-14-2006, 11:44 PM
Hi FlashGorden,

Yeah, i want to upload a file along with some data taken from a TextField.

Problem is that all other data exchange is done via remoting to a PHP class, what would be good is if i could use the remoting gateway for the file upload.

Problem is, that my image is going to one location and all other data (connected to that image), to another.

Regards, snapple :]

Flash Gordon
01-15-2006, 12:03 AM
I would image something like this would work. Once again I'm still foggy on exactly what you want.

obj.onComplete = function() {
//------------
_txt.text = "All Done";
rec_mc.clear();
upload_butn.enabled = false;
gotoAndPlay(2);
//-----------------
var LV:LoadVars = new LoadVars();
LV.name = name_txt.text;
LV.comment = comment_txt.text
LV.sendAndLoad("updateDataBase.php", LV, "POST");
};

snapple
01-15-2006, 12:11 AM
I should really explain myself more, i have only refrained from doing so - because i was just kind of after a quick "yes, the FileReference class can have additional parameters appended" - that is not to say that i don't appreciate your help.

The problem:

The FileReference class uploads an image to a PHP script, whcih then duplicates the image (the file upploaded), scales it in proportion to a 100x100 thumbnail and a 600x600 larger image, then renames these two images, puts them in to two seperate directories, then deletes the original image uploaded and enters it (the two new file names) into a database.

But the users comments and name (from a textfield) are needed in the same table in the database too, i.e. are needed in the same PHP script.

Regards, snapple

Flash Gordon
01-15-2006, 12:13 AM
Do you mind attaching your PHP and Fla (Flash 7 & 8 version, and yes I know 7 doesn't have FR but i need the coding.?
I'll take a look.

snapple
01-15-2006, 12:20 AM
It's not really a matter of syntax or code, more a conceptual problem really. Thanks for your advice though, i'll figure something out.

Cheers FlashGorden.

Regards, snapple :]

Flash Gordon
01-15-2006, 12:24 AM
Okay, I guess you got most of it then except for "But the users comments and name (from a textfield) are needed in the same table in the database too, i.e. are needed in the same PHP script."

Here is probably what I would do:

get the user's comment and name etc and store if in a empty movie clip on _root. When you send the info to the databases, get the names from the mc on _root.

I'll try to make an example a little later.

Good luck!

snapple
01-15-2006, 12:01 PM
No that woldn't help me. I'll explain my setup:

In Flash the user must:

1) Upload an image.
2) Fill in 2 TextFields for their username and comments about the image.

When someone clicks the 'upload' button in Flash, the FileReference object is pointing towards:


fileListener.onSelect = function( selectedFile:FileReference ):Void
{
fileField.text = "Attempting To Upload ";
selectedFile.upload( "http://localhost:8080/drawingApp/phpScripts/flashTemplate.php" );
}


Fine, thats all good. When the PHP script receives this file reference sent form Flash it does a few things:

1) Duplicates the image.
2) Resizes 1 image to 100x100 and the other to 600x600.
3) Rename both the newly created images.
4) Moves the 2 new (resized) images to 2 seperate directories on the server.
5) Deletes the original image as it is no longer needed.

What it should do next is insert both the new images, along with a usename and user comments into a database.

But where are the username and user comments? I can't get hold of them... they don't travel along with the FileReference object and I can't send the FileReference object along withe Remoting Gateway.

So how do end up with all my variables in 1 PHP script?

Hope this makes things clearer?

Regards, snapple :)

snapple
01-15-2006, 03:11 PM
OK, so theres really only two options:

1) Send extra parameters along with Flash 8's FileRerference Object.
2) To point my upload script for the file upload to the Remoting class.

I am going to make a query string and do option umber one, that way i can have all of my data in 1 PHP file (which is my end goal).

It's a little scrappy because all other data exchange is done via remoting - but i can't be bothered with Flash's poor excuse for a langauge any more!

So, my idea is (cut down version):


selectedFile.upload( targetScript+"?userComms="+ _root.userComments.text );


And my PHP:


$userfile = $_FILE["Filedata"]["tmp_name"];
$userfile_name = $_FILE['Filedata']['name'];
$uploaderComments = $_POST["uploaderComms"];

$tmpLogFile = fopen( "myLog.txt", "w" );
fputs( $tmpLogFile, "Upload data from Flash: " . $userfile_name );
fclose( $tmpLogFile );


But i don't get anything in my temporary log file - nothing is being sent to Flash. in fact, even when i just send the file with no additional data, i still can't get it to show the file name sent from Flash.

Any help would really help me, becuase i am on the verge of just going to the pub instead.

Regards, snapple
But when i try and write this value to a text file in PHP, i don't get anything, i

snapple
01-15-2006, 04:25 PM
Phew, all sorted with:



fileListener.onSelect = function( selectedFile:FileReference ):Void
{
fileField.text = "Attempting To Upload ";
var targetScript:String = "http://localhost:8080/drawingApp/phpScripts/newFlashTemplate.php";
selectedFile.upload( targetScript+"?uploaderComms="+ _root.uploaderComments.text +"&uploaderName="+_root.uploaderName.text );
}


Regards, snapple :]