Output existing JPEG image. [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wvxvw
Forum Newbie
Posts: 22
Joined: Sat May 17, 2008 10:55 am

Output existing JPEG image. [SOLVED]

Post by wvxvw »

Hi again.
I'm trying to send JPEG file to the HTML page which requests it, here's what I've done so far:
image.class

Code: Select all

<?php
class Image {
    static $dbUser = "******";
    static $dbPassword = "******";
    static $dbLocation = "******";
    static $dbAll = "******";
    static $tbImages = "******";
    
    function getImage($guid) {
        $con = mysql_connect(Image::$dbLocation, Image::$dbUser, Image::$dbPassword);
        if (!$con) exit ("Can not connect");
        $res = mysql_select_db(Image::$dbAll);
        if (!$res) exit ("failed to select DB");
        $res = mysql_query("SELECT * FROM " . Image::$tbImages . " WHERE id = " . $guid . " LIMIT 1");
        if (!$res) exit ("no such image");
        $row = mysql_fetch_assoc($res);
        if (!file_exists($row["imagepath"])) exit ("image was moved");
        header("Content-type: image/jpeg");
        readfile($row["imagepath"]);
        mysql_close($con);
    }
}
?>
i.php

Code: Select all

<?php
require_once("image.class");
if (isset ($_REQUEST["guid"])) {
    Image::getImage($_REQUEST["guid"]);
}
?>
I've read about not sending any data back to browser before sending header, but, seems like this is not the case... Anyway, the file does exist, but, somehow it doesn't show in the browser...
I should be missing something basic...

--------------------------
oooops... never mind... found the prob. I've saved php files in UTF-8 and the browser was reading unicode signature before it got header.
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: Output existing JPEG image.

Post by vargadanis »

if solved please put a [ SOLVED ] mark in the title of the topic... This way we are not gonna look at it. :P
Post Reply