You are here: Re: outputing image directly to browser « PHP Programming Language « IT news, forums, messages
Re: outputing image directly to browser

Posted by Mohawk Mawk on 06/08/07 19:43

i had the same problem that i would only see the weird text when i
tried outputing an image
check this :)
http://bjorntoday.com/pico.php?ID=20
this outputs a string as an images i can use the <img> tag no problem
because of header()

<?
header('Content-type: image/jpg'); //watch out that you have no white
spaces before <? or header throws a fit
$IMG= //your image string
print $IMG;

?>

i got my pictures saved in a database as blob so this is very
practical, yet i had the problem that the pictures where not caching,
so i got a lil help from the php manual, this works
<?

// Checking if the client is validating his cache and if it is
current.
if (isset($headers['If-Modified-Since']) &&
(strtotime($headers['If-Modified-Since']) == $TIME)) {// Client's
cache IS current, so we just respond '304 Not Modified'.
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $TIME).'
GMT', true, 304);
} else {// Image not cached or cache outdated, we respond '200 OK'
and output the image.
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $TIME).'
GMT', true, 200);
header('Content-type: image/jpg');
print $IMG;
}
?>

$TIME in my case is stored in the database as well.

 

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

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