0

我编写了这段代码来使用PHP 脚本Flex发送数据。

这是弹性代码:

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

这是PHP代码:

        public function returnRandomImage(){
            $contents = file_get_contents("images/code_complete2.png");
            header('Content-Type: image/png');

            return $contents;
        }

事情是:我真的对使用 PHP 发送图像文件很感兴趣,这样我就可以渲染它并在 Flex 中使用它。但是,当我使用.send()这个 HttpService 时,我得到的只是一个带有此消息的错误事件:(我已经尝试过使用header()功能和不使用它)。

(mx.messaging.messages::AcknowledgeMessage)#0
 body = "PNG"

就是这样。希望有人可以提供帮助。如果没有办法为此使用HttpService(即发送图像文件),那怎么办呢?我已经在我开发的应用程序中看到了它,所以我很肯定它可以完成。

编辑也添加了 PHP 代码。

4

2 回答 2

2

您可以使用 Base64 对图像进行编码,这样您就可以将其作为文本发送和接收。

http://www.google.es/search?sourceid=chrome&ie=UTF-8&q=as3+base64+encoder

于 2011-06-30T23:34:19.450 回答
0

我会假设您正在尝试在 flexHTTPservice 请求时将图像从 php 发送到 flex

您必须确保在 php 端正确设置标题

// 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"




如果您要将图像从 Flex 发送到 PHP,那么您必须对其进行 base64 处理以获得最佳效果。

[编辑]

// 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 )
于 2011-06-30T23:47:30.430 回答