Hi,

Friday, March 25, 2005, 3:27:41 AM, you wrote:
WS> Hello,

WS> I really can't figure this out. Can someone help please. I've wasted hours
WS> already with this one.

WS> I'm trying to print image to a web page using fpassthru. Here's the code:

WS> $name = path/to/the/image/folder/img1.jpeg;
WS>  $fp = fopen($name, 'rb');

WS>  // send the right headers
WS>  header("Content-Type: image/jpeg");         //also tested with type pjpeg
WS>  header("Content-Length: " . filesize($name));

WS>  // dump the picture
WS>  fpassthru($fp);

WS> Help Appeciated. Thanks.
WS> -Will

Make sure you don't have any whitespace after the trailing ?> if there
is one, better still get rid of it.
Also I use readfile($name); ... can't remember why


Here is a bit of code I use for passing PDF files which also handles
caching control you can adapt easily for images.


<?php
$cache_time = false;
$requested_time = false;
$filename = $_REQUEST{'filename'];
if(file_exists($filename)){
  $len = filesize[$filename);
  $mtime = filemtime($filename);
  $cache_time = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
  header('Last-Modified: '.$cache_time);
  $rt = false;
  if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
    $rt = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
  }
  if($rt) $requested_time = strtotime($rt);
  if($requested_time && $cache_time){
    if($requested_time == $cache_time){
      Header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
      exit;
    }
  }
  header("Accept-Ranges: bytes");
  header('Cache-Control: no-cache, must-revalidate');
  header("Content-type: application/pdf");
  header("Content-Length: $len");
  readfile($filename);
}

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to