I'm uploading an image using PHP and storing the file name in the db. For ease of administration, I am using the same filename for the old image and the new image. Basically I'm using the username as the filename, so old image was:
username.jpg
and the new image after being uploaded is renamed and overwrites
username.jpg
Once the upload is successful, and the user returns to their account managment panel, the image being shown is still the old image. If I refresh the page, it shows the new image.
So I have header() code at the top of the page like so:
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
but to no avail, still need to refresh to see the page.
I even tried loading the image as a 1x1 version of it self on the upload success page, thinknig that it would load the old image here, then when user clicked link to go home, they would have the new image shown to them on this subsequent page.
Please let me know if there is anything I can do to get around this. Even if it means sending the user through some redirect page to make sure the cache gets purged, so the new image can load.
I also thought that I could come up with some code to refresh the page only once, but thought that might be overkill. (like send user to account managment page with a ?refresh=yes query string, then if this query string exists do a
header("Location: ...php");
to refresh the page without the query string so that it wasn't triggered over and over.
Let me know your thoughts on the best way around this, so that users don't have to be instructed to refresh the page manually (which is what i'm doing now).
I've ran into this issue before, but want to get it handled now and forever. :p
Thanks!