Output existing JPEG image. [SOLVED]
Posted: Sat Jun 21, 2008 2:05 pm
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
i.php
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.
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);
}
}
?>Code: Select all
<?php
require_once("image.class");
if (isset ($_REQUEST["guid"])) {
Image::getImage($_REQUEST["guid"]);
}
?>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.