?
Solved

Avoid image caching after file upload

Posted on 2008-09-29
3
Medium Priority
?
1,574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

764 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