I've written this piece of code to use a PHP script to send data to Flex.
Here's the Flex Code:
<s:HTTPService id="imageService" url="http://localhost/bookView/amfphp/services/ImageServer/showImage.php"
useProxy="false"
method="POST"
result="handleImageResult(event)"
fault="handleFault(event)"
showBusyCursor="true">
<s:request xmlns="">
<bdla>"lashf"</bdla>
</s:request>
</s:HTTPService>
Here's the PHP code:
public function returnRandomImage(){
$contents = file_get_contents("images/code_complete2.png");
header('Content-Type: image/png');
return $contents;
}
Thing is: I'm really intereste开发者_运维知识库d in using PHP to send an image file, so that I could render it and use it in Flex. However, when I .send()
this HttpService, all I get is a fault event with this message: (I've tried both with the header()
function and without it).
(mx.messaging.messages::AcknowledgeMessage)#0
body = "PNG"
That's it. Hope someone can help. If there is no way to use HttpService for this end (i.e. send image files), how can one do it then? I've seen it in an app I worked on so I'm positive it can be done.
EDIT Added PHP code too.
You can encode the image using Base64, this way you can send it and receive it as text.
http://www.google.es/search?sourceid=chrome&ie=UTF-8&q=as3+base64+encoder
I will assume you are trying to send an image from php to flex when the flexHTTPservice requests it
You have to make sure the header is set correctly on the php side
// this method should be used if you have the image inside a database
header('Content-type: image/png');
echo $image;
//if the image is just an image on the server then you just need to point the HTTPService to the url "http://mydomain.com/testimage.jpg"
If you are sending an image from Flex to PHP then you have to base64 it for best results.
[EDIT]
// I would use a loader or the Flex Image component to work with images.
var antiCache:Date = new Date( );
_source = val + '&noCache=' +antiCache.getTime();
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
_loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler )
_loader.load(new URLRequest(encodeURI(_source)));
addChild( _loader )
精彩评论