Hi, sorry if this is a PHP question....I'm trying to work with this more
on the Flash side, so I hope its a Flash question.
I have a PHP script online that serves to write binary image data from
my Flex/AIR app:
$f = fopen($path,"w");
fwrite($f, $GLOBALS[ 'HTTP_RAW_POST_DATA' ] );
fclose($f);
On the Flash side:
var jpgtosave:JPGEncoder = new JPGEncoder();
var rawdata:ByteArray = jpgtosave.encode(bitmap);
var header:URLRequestHeader = new URLRequestHeader ("Content-type",
"application/octet-stream");
var myRequest:URLRequest = new URLRequest (path);
myRequest.requestHeaders.push (header);
myRequest.method = URLRequestMethod.POST;
myRequest.data = rawdata;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(myRequest);
This works great, but now I want to use that same PHP script to upload a
text file. The reason I want to keep the PHP script the same is because
the end user actually sets the upload location, and I think it would be
overly complicated to have them choose two different upload script
locations.
Anyway, no matter what I try, the text file that's written to the server
is done correctly, except the contents of it are always the file's URL
instead of the text that I wanted. I realize there are better ways to
upload text through PHP, but as I said, I'd like to use the same script
as my JPG uploads.
Here's some things I tried:
1. Changing the request header to "Content-type", "text/plain"
2. Changing the URLLoaderDataFormat to TEXT
3. Writing out my text's string to binary through ByteArray.writeObj
4. Taking my binary data directly from a FileStream
So, as you guys can see I'm stabbing in the dark! I assume that I'm
somehow encoding the data wrong to get to the server. Maybe I need a
file header as the com.adobe JPGEncoder gives the JPG a header, likewise
I should give my text file a header. Does it have to be binary data to
use with my PHP script?
Thanks!
ben
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com