Solved

Avoid image caching after file upload

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now