TwelvestoneFlash

FileReference, uploading a file along with other data


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
baron ruhstoff
 
2008-09-09

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)?

JLM
 
2008-09-10

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.

jestros
 
2008-09-10

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.

baron ruhstoff
 
2008-09-10

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. :(

jestros
 
2008-09-11

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; }

baron ruhstoff
 
2008-09-12

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!

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

FileReference, uploading a file along with other data