Solved

Avoid image caching after file upload

Posted on 2008-09-29
3
1,569 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

816 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

8 Experts available now in Live!

Get 1:1 Help Now