보안문제때문에 인증없이 이미지를 웹서버에서 직접 보여주게 하고 싶지 않을때 php 같은 서버쪽 프로그램에서
세션을 확인하고 보내주게 된다.
이를 flex image 컨틑로에서 보여주게 하려고 했다.

하지만 너무 쉬워서였나 이와 관련된 내용을 찾기가 어려웠고 3일정도 자료찾고, 시도해보고 하다가 겨우 성공했다.
하고나니 간단하네...크...

서버쪽 코드 : imgdown.php
<?php
$file = $_GET['file'];
if (file_exists($file))
{
    // Note: You should probably do some more checks
    // on the filetype, size, etc.
    $contents = file_get_contents($file);

    // Note: You should probably implement some kind
    // of check on filetype
    //header('Content-type: image/jpeg'); 주석을 해도되고 풀어도됨
    echo $contents;
}
?>

클라이언트쪽 코드 :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

 <mx:Script>
  <![CDATA[
   import mx.rpc.events.ResultEvent;
   public var req:URLRequest = new URLRequest("http://localhost/imgdown.php");
   public var loader:Loader = new Loader();
     
   private function clickImage():void {
     var variables:URLVariables = new URLVariables();
     variables.file = "D:/Winter.jpg";
     req.data = variables;
    loader.contentLoaderInfo.addEventListener( Event.COMPLETE, completeHandler );
    loader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, onLoadError );
     loader.load(req);
   }
         private function completeHandler(event:Event):void {
          var bmp: Bitmap = ( event.target as LoaderInfo ).content as Bitmap;
          imgPic.source = bmp;
         }   
   private function onLoadError( event: IOErrorEvent ): void
   {
    trace('error', event);
   }
  ]]>
 </mx:Script>

 <mx:Image x="10" y="10" width="167" height="163" id="imgPic"/>
 <mx:Button x="10" y="181" label="이미지보기" id="btnImage" click="clickImage()"/>

</mx:Application>

=========================================================

서버에 D:/Winter.jpg 라는 이미지를 놓고 해보면 된다.
imgdown.php은 웹서버 루트에 놓고, flex를 실행하면 이미지가 보인다.

처음엔 Loader 가 아닌 URLLoader로 했는데 그래서 오래걸렸다.


php.ini 제일 아래에 다음과 같이 작성한다.

[Zend]
zend_extension_manager.optimizer_ts="D:/APM_Setup/Server/ZendOptimizer/lib/Optimizer-3.3.0"
;zend_extension_ts="D:/APM_Setup/Server/ZendOptimizer/lib/ZendExtensionManager.dll"
zend_extension_ts="D:/Data/Apps/XDebug/php_xdebug-2.0.5-5.2.dll"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

+ Recent posts