Php – Get info after fileReference upload

actionscript-3file uploadflashPHPupload

Normally when I send information to PHP scripts via URLLoader, I have the PHP return various success codes so I can have my Flash files respond according to whatever success code the PHP returns (0 is a failure, 1 a success, 2 is some other error code, etc.).

Now I'm trying to submit a form with a bunch of data in it (name, email, birthday, etc.) as well as upload a file. I'm using fileReference to upload the file and send the additional variables along with the upload request. The information is making it to my PHP file fine. However, I can't find any way to get information BACK from the PHP file. That is to say, I want the PHP to echo "success=1" if the file is successfully loaded, "success=2" if there was an error inserting the data into the MySQL database, etc., but currently I can't figure out how to get info from the PHP. Normally I could just look at _myURLLoader.data but in this instance I need to reference _fileReference.data which is actually the bitmap data of the file.

Anybody have any ideas?

Thanks!

–eric

Best Answer

You can use the http status to tell flash what happens when you upload a file.

On the php side, to tell flash the file was not received I do the following:

if(!isset($_FILES['Filedata']['name']))
{
header("HTTP/1.x 500");
print "RESULTS=FAIL";
exit();
}

If the file is larger than what I want:

if(!isset($_FILES['Filedata']['size']) > $maximumuploadsize)
{
header("HTTP/1.x 406");
print "RESULTS=FAIL";
exit();
}

Etc.

Then on the flash side I'll setup an .onHTTPError listener such as:

photo.onHTTPError = function(file:FileReference, httpError:Number)
{
switch (httpError)
{
case 500:
// Handle missing file
break;
case 406:
// Handle file too large
break;
}
}

Bill H