Re: [PHP] Dynamic Display of Images Stored in DB



On Thursday 29 November 2007 06:03:32 Chris wrote:
In my solution, I use two scripts. One for showing the image true size
and another for generating a thumbnail -- I may be wrong, but I think
it's better to generate a thumbnail as needed on the fly than it is to
store both images (large and thumbnail) in the dB.

Cache it on the filesystem even if it's for a short time (of course if
the image is updated elsewhere the cache needs to be cleared as well..).


<?php

$file = '/path/to/cache/file.jpg';
if (file_exists($file)) {
if (filemtime($file) > strtotime('-30 minutes')) {
$fp = fopen($file, 'rb');
fpassthru($fp);
exit;
}

// the file is older than 30 minutes, kill it and start again.
unlink($file);
}

// continue creating your thumbnail.

$fp = fopen('/path/to/cache/' . $filename, 'wb');
fputs($fp, $imagecontents);
fclose($fp);

// display image


Hell, I'm all ok with this method... but does (different) webhotells take into
account the amount used with cache/temp files.
If so, some check should be used, and if not. Cache it all!, and remove the
timelimit, some check for the change of image of course, but that all depends
if you acctually change images from time to time..


--
Postgresql & php tutorials
http://www.designmagick.com/



--
---
Børge Holen
http://www.arivene.net
.



Relevant Pages

  • Re: [PHP] Dynamic Display of Images Stored in DB
    ... account the amount used with cache/temp files. ... Cache it all!, and remove the timelimit, some check for the change of image of course, but that all depends if you acctually change images from time to time.. ... If it's under your user account then there's no way for them to know which parts of your website are cache/temp folders and which aren't. ...
    (php.general)
  • Re: Pictures wont store in users cache
    ... Then I opened the page and then checked my browser cache files, ... This will open the images in a new browser window and when the user closes the ... I've built a web site and none of the pictures I've put into it are caching and the photo gallery (100+ pictures with auto thumbnail) thumbnail doesn't cache either. ...
    (microsoft.public.frontpage.client)
  • Re: Two Explorer thumbnail bugs
    ... > has changed) - it is an incorrect thumbnail. ... Modify your script/program to mark the ... Thumbs.db to be "deleted" in the folder if a picture is changed in this ... I am assuming that the deleting the cache is safe ...
    (microsoft.public.windowsxp.photos)
  • Re: Image thumbnail and image different
    ... This is related to the thumbnail cache. ... file under a new filename, or going to Folder ... Is this some form of XP display problem? ...
    (microsoft.public.windowsxp.general)
  • Re: Image thumbnail and image different
    ... right-clicking on it and selecting "Refresh Thumbnail." ... because XP saves the thumbnail for the original image in its cache and not ... create a new cache for that directory. ... Is this some form of XP display problem? ...
    (microsoft.public.windowsxp.general)