caching - Cache php-generated image until it changes -


I apologize in advance for the lack of knowledge on this topic; I have seen many other posts but they can not find any solution for me to work.

However, I am using a dynamic displayimage.php file that shows the users profile page of the site on which I am working, the page takes an id parameter , And pulls the image file name from a mysql database here (short) code:

  $ id = mysql_real_escape_string ($ _ GET [id]); $ Table = "images_user"; $ Idname = "userid"; $ Upload Dear = "/ home / username / upload / picture / user"; // External Web Route $ select = mysql_query ("SELECT * FROM $ table WHERE $ idname = '$ id' LIMIT 1); if (mysql_num_rows (select $)>) {$ file = mysql_fetch_assoc ($ of Select;); header ("content-type: $ file [mime type]"); readfile (. $ Uploaddir $ file [name]);}   

Currently, because it is a The php file is generated, the image is not being cached, which actually slows down the site, so I add it:

  header ("Cash-Control: Private, Max- Age = 10800, pre-check = 10800 "); headers ("Pragma: Private"); Header ("End:". Date (DATE_RFC822, strontem ("2 Days"));   

The problem that solves, Great! Images are cached, and loads quickly.

However, users have the ability to change their profile pictures. When this happens, I save their uploaded photo , Delete the old, and update the database entry to point to the new picture Literacy am. But now, because the old picture still went to cash, they do not see the update unless they manually do the F5 page.

How can I get it to cache the photo, but a 'cache again' when the picture has been changed?

After uploading an image, add additional parameters in the URL to show the image, which is used as' displayimage .php 'is usually it will be a timestamp.

As with the usual case, do you displayimage.php? Id = 123123

And profile can reach the photo after updating, to refresh the image, do you see the displayimage.php? Id = 123123 and time = 1000121110 . The changing time parameter is bound to reload the image from the image every time, when the user updates the image.

Comments