PDA

View Full Version : Uploading image to a PHP page with other POST items that returns a URL


angerbee
03-15-2009, 11:00 PM
I am trying to create a Flex app that will allow the user to browse their computer for an image, then upload the image to the server.

I need to send this image to a PHP page that will require 2 other POST items (an order # and a password) along with the image that is then renamed and saved. The PHP page then echos the new file name back to Flex so that I can record it.

The locally running Flex app will then create an Image with the FileReference data to be manipulated locally:

var i:Image = new Image();
i.source = fileref.data;


However, I need the url of the uploaded image so that it can be referenced in an XML string that will later be uploaded so that the whole stage can be recreated on the server side.

So when I look at using FileReference.upload(URLRequest), I don't see how I can include the other variables I need, but when I use HTTPService, I can't tell what is happening when I do
httpsrv.send({id: id, pwd: pwd, img: fileref.data});

wvxvw
03-15-2009, 11:59 PM
You can try to add those parameters to the URL, where you uploading them (i.e. they will be available through $_GET array, while the file you send will be in the $_POST) Something like: www.example.com?id=someID&password=abcd. But I haven't tried it with FR, though with URLLoader it worked... But I'd rather have a hash string generated from ID and password, have it written to the session and send that hash (not the password and the name, since it is not secure).

angerbee
03-16-2009, 03:15 AM
Great idea using GET, that's perfect. But I am changing the filename in the PHP script, how am I supposed to get that name back using a FileReference?

wvxvw
03-16-2009, 12:02 PM
I'd think of something like this scenario:
After user successfully logs in s/he receives SID (i.e. you open a session for him/er).
When user uploads anything, s/he includes that SID into URL - so you can identify who's being sending what.
You write an entry into data base that reflects the operation been performed and session ID that requested that operation.
You may as well add listener to FileReference "uploadCompleteData" event and send one more request after the event is fired, again, including SID - so that you'll know which user requested information and for which operation.
Then, you search the table for proper session id and return the last operation(s) statistics.

DjKermit
03-25-2009, 10:08 PM
I need to send this image to a PHP page that will require 2 other POST items ...
uploadURLReq = new URLRequest();
uploadURLReq.data = new URLVariables();
uploadURLReq.method = URLRequestMethod.POST;
uploadURLReq.data.myVariable = 'myValue';

then in PHP
echo $_POST['myVariable']; // myValue

However, I need the url of the uploaded image...

Serv side script shuold print that url, then you'll get it via DataEvent.UPLOAD_COMPLETE_DATA