16 Replies Latest reply on Jul 13, 2009 11:37 PM by Madhav Subedi

    How use PHP to read image files from a folder and display them in Flex 3 tilelist.

    TCL9 Level 1

      Hello. I need help on displaying images from a folder dynamically using PHP and display it on FLEX 3 TileList. Im currently able to read the image files from the folder but i don't know how to display them in the TileList. This is my current code

      PHP :

      PHP Code:
      <?php
      //Open images directory

      $imglist = '';

      $dir = dir("C:\Documents and Settings\april09mpsip\My Documents\Flex Builder 3\PHPTEST\src\Assets\images");

      //List files in images directory
      while (($file = $dir->read()) !== false)
      {
      if (
      eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
      echo
      "filename: " . $file . "\n";
      }

      $dir->close();
      ?>

      FLEX 3 :

      Code:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="pic.send();">


      <mx:Script>
      <![CDATA[

      import mx.controls.Alert;
      import mx.events.FlexEvent;
      import mx.rpc.events.FaultEvent;
      import mx.events.ItemClickEvent;
      import mx.rpc.events.ResultEvent;


      public var image:Object;

      private function resultHandler(event:ResultEvent):void
      {

      image = (event.result);
      ta1.text = String(event.result);

      }

      private function faultHandler(event:FaultEvent):void
      {

      ta1.text = "Fault Response from HTTPService call:\n ";
      }

      ]]>

      </mx:Script>

      <mx:TileList x="31" y="22" initialize="init();" dataProvider = "{image}" width="630" height="149"/>

      <mx:String id="phpPicture">http://localhost/php/Picture.php</mx:String>
      <mx:HTTPService id="pic" url="{phpPicture}" method="POST"
      result="{resultHandler(event)}" fault="{faultHandler(event)}"/>



      <mx:TextArea x="136" y="325" width="182" height="221" id="ta1" editable="false"/>




      <mx:Label x="136" y="297" text="List of files in the folder" width="182" height="20" fontWeight="bold" fontSize="13"/>


      </mx:Application>

      Thanks. Need help as soon as possbile. URGENT.