By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,183 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,183 IT Pros & Developers. It's quick & easy.

Issue with cache and pictures

P: n/a
I have a problem with cached images...

The script first creates some pictures out of avariable source (every time
the script runs the pics are different):

$im = imagecreatefromjpeg($file);
imagejpeg($im2,"temp100.jpg",100);
imagejpeg($im2,"temp75.jpg",75);
imagejpeg($im2,"temp50.jpg",50);
imagejpeg($im2,"temp25.jpg",25);

then I show them using normal html img tags

<img src="temp100.jpg">

The problem is that the pictures are cached and the script/IE shows a
fautlhy version of the pictures.

I tried messing with the header as described in the php manual.

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

But this doesn't work... wrong pic-fileversion

Does anybody has a sollution?

Thanks
KJ
Jan 2 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jaak said the following on 02/01/2006 16:00:
I have a problem with cached images...

The script first creates some pictures out of avariable source (every time
the script runs the pics are different):

$im = imagecreatefromjpeg($file);
imagejpeg($im2,"temp100.jpg",100);
imagejpeg($im2,"temp75.jpg",75);
imagejpeg($im2,"temp50.jpg",50);
imagejpeg($im2,"temp25.jpg",25);

then I show them using normal html img tags

<img src="temp100.jpg">
This is a really bad way of implementing dynamically-generated images.
If more than one user is using your site, then you will get naming
collisions, files overwriting each other, users getting each other's
images, etc.

Much better to have an image-generating script (called, for example,
image.php), e.g.:

image.php
=========

<?php
header("Content-Type: image/jpeg");
/* ... cache-control headers here ... */

/* ... need validation of $_GET fields here ... */
$im = imagecreatefromjpeg($_GET["file"]);
imagejpeg($im, '', $_GET["quality"];
imagedestroy($im);

?>

Then in your HTML, you can call it thus:

<IMG src="image.php?file=file.jpg&amp;quality=50">

The problem is that the pictures are cached and the script/IE shows a
fautlhy version of the pictures.

I tried messing with the header as described in the php manual.

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


Where are you putting these headers?

Headers sent with the HTML affect *only* the HTML file, not any embedded
resources (i.e. images).

The solution is to send the appropriate headers with the image files, as
is possible with the image.php implementation above.
--
Oli
Jan 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.