Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts

    Displaying PJPEGs from a DB

    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.)


    PHP Code:
    $q 'SELECT name,type,file,size FROM file WHERE id='.$db->qstr($_GET['id']);
            
    $db->StartTrans();
            
    $row $db->GetRow($q);
            
    $file=$row['file'];
            
    $size $row['size'];
            
    $type=$row['type'];
            
                
    $db->maxblobsize=1000000;
                
    $filename $db->BlobDecode($file);
                            
    $db->CompleteTrans();
                    
    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;
                exit(); 

  • #2
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "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

    I take no responsibility for the above nonsense.


    Left Justified

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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
    Code:
    <?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'
      xmlns:exif='http://ns.adobe.com/exif/1.0/'>
      <exif:ColorSpace>4294967295</exif:ColorSpace>
      <exif:PixelXDimension>2708</exif:PixelXDimension>
      <exif:PixelYDimension>2248</exif:PixelYDimension>
     </rdf:Description>
    ...
    (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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •