Q:

AS3 Load PNG from PHP

I need some help with loading a PNG file from a server into my flash project. What I want to do it be able to call a PHP page and send it a variable which I can do. Then I want to access a db and get a path for the image, I can do this too. What I'm not sure about is what to do then.
What I need to happen is the PHP to return the PNG to flash somehow. Can I just add the PNG to the php page and use a loader somehow? I've been searching around google but most tutorials seem to be getting PNGs out. 
Thanks
Ben

A:

It is actually pretty easy.  : )
<?php
    // do some mysql magic.
    // let's assume you get a filename back as $file_name;

    header('Content-type: image/png');
    readfile($file_name);

Note that you may have to include some path info as well.  Not sure where your images are stored, but if the image are in /var/www/public/images, you'd wany to prepend that into your file_get_contents call.        

Added:  also, if you just want to return a path to the PNG, you can do a URLRequest to a PHP file, let it figure out where the image lives, and return a URL.  This is even easier... I'd just recommend standardizing on a data interchange protocol like XML or (even better) JSON... that way, if you ever decide that you want to break out of Flash and into browser technologies, your backend will already be waiting for you.
<?php
    // do some mysql magic.
    // let's assume you get a filename back as $file_name;

    $retVal = array('pathname'=>$file_name);
    header('Content-type: application/json');
    echo json_encode($retVal);

