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

Dyanmic Images Reload

P: n/a
I have a php script that dynamically creates images, reusing image files on
the server to save space and clutter.

The problem is described in the steps below:

1. User clicks on a button.
2. Same page loads, but the php script creates a new image in an old file.
3. It displays the image file, but the old image shows, even though the file
contains the new image.

My options are:

1. Use javascript to force a reload when the user clicks the button (not
desirable, because the user is forced to confirm the reload by the browser).
2. Put a cheesy blurb on the page telling the user to reload or refresh
(along with ideotic explanations of how to do it).
3. Some really great way someone here is going to describe to me (my
preference).

Rex
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

STEPHEN GOODE wrote:
3. Some really great way someone here is going to describe to me (my
preference).


Add a 'please don't cache me' header to the script creating the image
files. See http://www.php.net/manual/en/function.header.php

NB header() lines must all be issued before any other output is sent to
the browser (but you knew that already). Something along the lines of:

<?php
// a date in the past...
header( "Expires: Sat, 18 Mar 2000 00:00:01 GMT" );
// hint...
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" );
// don't cache me...
header( "Cache-Control: no-cache, must-revalidate" );
// no, really...
header( "Pragma: no-cache" );
// it's a piccy...
header( "Content-type: image/jpeg" );
....
// rest of image code...

?>

---
Steve

Jul 17 '05 #2

P: n/a
Do you need to reload the whole page, or will refreshing the image be
enough?

Maybe just use js to reload only the image.

document.images["imgName"].src="getImage.php?blah="+escape(new
Date());

or something like that. Adding a fake querystring to your image src
will persuade the browser to refetch the image instead of using the
cached version. You might also experiment with adding "no-cache"
headers to your image when you serve it up.

Tim.
"STEPHEN GOODE" <re******@verizon.net> wrote in message
news:oXYxd.3602$hc7.1541@trnddc06...
I have a php script that dynamically creates images, reusing image
files on the server to save space and clutter.

The problem is described in the steps below:

1. User clicks on a button.
2. Same page loads, but the php script creates a new image in an old
file.
3. It displays the image file, but the old image shows, even though
the file contains the new image.

My options are:

1. Use javascript to force a reload when the user clicks the button
(not desirable, because the user is forced to confirm the reload by
the browser).
2. Put a cheesy blurb on the page telling the user to reload or
refresh (along with ideotic explanations of how to do it).
3. Some really great way someone here is going to describe to me (my
preference).

Rex

Jul 17 '05 #3

P: n/a
Steve,

Thanks. I couldn't get it to work. It all seemed to be working. I mean, the
header calls were all done right and before any other output, but it still
cached those images.

What worked was what Tim suggested in another reply. I'm still hoping to
figure out why the headers didn't work.

Thanks again.

Rex
Jul 17 '05 #4

P: n/a
Tim,

Thanks. That worked. Don't know why the no-cache stuff didn't work, but I
plan to figure it out.

Rex
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.