Adam Adam - 1 year ago 81
PHP Question

Loading an image through PHP

I'm trying to load an image through PHP, but I don't know how.
The filename is stored in the database, such as


// Client requesting image, so retrieve it from DB
$id = mysql_real_escape_string($_GET['image']);
$sql = "SELECT * FROM $tbl_name WHERE id = '$id' LIMIT 1";

The client needs to request an image like so

And then it should return the image, so it can be embedded like this:

<img src="" alt="" />

Is this possible?

Answer Source
$img = 'path/to/image.jpg';
header('Content-Type: image/jpeg');

just tested it