You are here: Re: [PHP] image problem « PHP « IT news, forums, messages
Re: [PHP] image problem

Posted by Tom Rogers on 03/25/05 03:30

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация