Solved

Avoid image caching after file upload

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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)

729 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