View Full Version : Displaying PJPEGs from a DB

11-01-2005, 04:54 PM
The code below works fine when the images are gifs or jpegs, but for pjpegs, it doesn't. Is there something I'm missing?
(the following is called from html pages as <img src="image.php?id=xxx" />, and the $db->xxx bits are using ADODB, which is a database-abstraction layer.)

$q = 'SELECT name,type,file,size FROM file WHERE id='.$db->qstr($_GET['id']);
$row = $db->GetRow($q);
$size = $row['size'];

$filename = $db->BlobDecode($file);
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false); // required for certain browsers
header("Content-Type: ".$type);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$size);
echo $filename;

11-02-2005, 02:22 AM
"it doesn't work"
How doesn't it work?
What happens?
Is the behaviour browser specific?
What mime-type are you sending (I'm assuming image/pjpeg) -- have you tried sending 'image/jpeg' and 'image/x-citrix-pjpeg' for pjpeg files?

We need details if you want help :)

11-02-2005, 04:40 AM
Have you considered just storing the path and filename to the images in the database? If you lose your database you won't lose your images that way.

11-02-2005, 09:53 AM
Have you tried just calling the page alone in a browser with a known image id=NN?

Have you tried just running the query alone?

Personally I'm with Spookster on the issue of using the file system rather than database for storing images.

11-02-2005, 09:56 AM
Storing the files isn't really an option.

As for "it doesn't work", when embedded in HTML, no image appears. When viewed directly (loading image.php in a browser) the "this image cannot be contained because it contains errors" is displayed.

Further tinkering has revealed that it isn't being a PJPEG that makes it not work, as a few that I have do (so rule out a mime-type problem). It seems (so far...testing with thousands of files is tricky) that those images that don't work have some adobe information inside them. Opening the file in a text-editor (or viewing the source) reveals

<?adobe-xap-filters esc="CR"?>
<x:xapmeta xmlns:x='adobe:ns:meta/' x:xaptk='XMP toolkit 2.8.2-33, framework 1.5'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>

<rdf:Description about='uuid:5b966e90-4481-11da-bfd7-c86ce1527b2f'

(there's a lot more of it...)

Could this be the problem, or is it just a coincidence? And what can be done?

OK, as I'm typing this I was just trying some other things, and it seems that Opera has no problem viewing the images, just IE and Firefox