I've uploaded files before. I've posted form data before as well. For some reason I'm drawing a blank when it comes to doing both at once. :(
Say you have a form that asks the user to upload a file and give it a plain English name. How would you go about posting both pieces of info (i.e. the file and the string)?
guessing, and shoving it all in one line simplified, flash might look like...
_fileRef = new FileReference() _fileRef.addEventListener( Event.SELECT, function (e){ _fileRef.upload( new URLRequest( _uploadPath+'?PictureId='+_imageId+'&cacheKiller='+(new Date()).getTime()) ) ); });
I can't really guess at php but I have some code that might be hackable, but none of this might work and you might need two trips or pass the name to javascript and get php to get it there or you can just store it and then get back as xml on a listener where you stored it which is fine if loading image into flash next.
You are using php for the backend? I've only done it with image files, but this looks to be pretty much the same.
$uploaddir = '/var/www/uploads/'; $uploadfile = $uploaddir.$_POST['userfilename'].$basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
But you might want to make sure you have unique names.
Maybe I should clarify a bit... The form collecting the data has a bunch of fields in addition to file selection (e.g. name, favorite color, preference for lemurs over hookers, etc.). I'm hoping to post everything in one fell swoop. Handling things on the backend isn't a problem - where I'm stuck is figuring out how to build the data object that gets posted.
Posting the data from a bunch of text fields? No problem. Uploading a file? No problem. Doing both at the same time? Problem. :(
This seem like it would be the easiest way. When they hit submit, run two functions one to upload the file
upload(fileinfo);
and data
buildDataObj(textField1, textField2);
and the 2nd function would look something like
function buildDataObj(textField1, textField2) { customerPrefs.favColor = textField1; customerPrefs.lemurSex = textField2; }
Yep, it's looking like two separate calls are the way to go for this one. In the future, though, I think I'll play around with UploadPostHelper.as and see if I can get it to work with actual files and not just bitmapdata.
Thanks!