1 Reply Latest reply on Dec 9, 2009 3:33 PM by forsythes

    Checking if a URL points to a valid image file.

    Gregory Lafrance Level 6

      I'm creating a media browser, pulling in image links from Google AS API

      .

       

      Sometimes for some reason one of the image urls is invalid, because I get the broken image icon in my Tile container populated by a Repeater.

       

      How can I check to see if the url actually points to a valid image?

        • 1. Re: Checking if a URL points to a valid image file.
          forsythes

          Assuming that your HTTPService looks something like this...


          MXML

           

           

              <mx:HTTPService id="phpService" url="imageCheck.php" resultFormat="e4x" method="POST">

                  <mx:request xmlns="">

                        <formData>

                          <image>

                              <imageURL>{imageURLInput.text}</imageURL>

                           </image>

                        </formData>

                  </mx:request>

              </mx:HTTPService>

           


           

          You can always call a php file to check to see if the image exists. Then you can return the result as XML to Flex.

           

          PHP (imageCheck.php)

           

          <?php

           

          //Get the image URL from Flex form

          $myImage = $_POST['imageURL'];

           

          //Check to see if the image exists by trying to get the image size properties of it.

          $url=getimagesize($myImage);

          if(!is_array($url))

          {

          $myImage =”notFound.jpg”;

          }

           

          //Write the XML file for Flex to use

          $xml_output = "<?xml version=\"1.0\"?>\n";

          $xml_output = "<formData>";

          $xml_output = "<image>";

          $xml_output = "<imageURL>".$myImage.</imageURL>";

          $xml_output = "</image>";

          $xml_output = "</formData>";

           

          echo $xml_output;

           

          ?>