Solved

Avoid image caching after file upload

Posted on 2008-09-29
3
1,567 Views
Last Modified: 2013-12-25
Hi,

I have multiple upload form on the same page to allow the user to upload images. On postback I process the image uploaded and display it as a thumbnail just beside the correspondant upload form. The problem is that the image displayed is not the new one but the old one (probably get from cache).

If I upload a new picture that doesnt exists on the system, I see it immediatly.
Same thing if a delete one of the picture, it disappeared immediatly.

The problem came when I overwrite an existent picture.

I tried bunch of things like :

<meta http-equiv="Expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
<meta http-equiv="Pragma" content="no-cache">

or in php :

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
header("Pragma: no-cache");

Please see the attach files, one is the html result, the other the php code to understand the logic of my page.

Thanks a lot!

example.txt
phpcode.txt
0
Comment
Question by:ITMax87
  • 2
3 Comments
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22599489
You may have to use sessions to  to set a session to  force the browser to a new session each time they go, and thus make the browser get the page from the server instead of the cache

PHP Code:
<?php
session_start();
$_SESSION = array();
session_destroy();
?>

Try that at the very top of the PHP page, see what happens.  You are trying to force the browser to get the new image from the server EVERY time.
0
 

Author Comment

by:ITMax87
ID: 22601723
Ok but what if I dont want to destroy my session. In need some info that are stored in $_SESSION.

I tried session_regenerate_id() just in case.. without success

Any other idea ?
0
 
LVL 44

Accepted Solution

by:
scrathcyboy earned 500 total points
ID: 22601811
you didn't say you had an active PHP session  -- had you said so, it would have saved a lot of time.

http://us3.php.net/session_cache_limiter
http://us.php.net/header
http://www.webmasterworld.com/forum88/1003.htm
http://www.usenet-forums.com/archive/index.php/t-20949.html
http://php.oregonstate.edu/manual/en/function.session-cache-expire.php

You will find generally that a cache clear, clears the sessions too, but there are ways around this.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now