SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    minor uploading images problem

    Hi,

    I store an image field "image/8.jpg" in a database and store the image in a directory c:\image. If the user doesn't like this image, he can upload a new one using the same image name, so now the new image has the same field name "image/8.jpg". (upload, copy, and overlap it)

    My problem is when I view the new image, it displays the old image. Then I press "refresh" button of Windows Explorer after the script displays it, it will display the new image correctly.

    The new image in folder c:\image is there every time, so uploading is ok...

    What's the problem?...is this something to do with browser caching?

    Thanks in advance,
    John

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Exactly. You have to force the browser not to cache that image. You can do that with meta tags or http headers. I am not real familar with either of those, but you can try this until someone gives you more guidance:

    <meta http-eqiv="expires" content="Mon, 22 Nov 1999 09:27:00 EST" />

    Include that between the <head> tags.

  3. #3
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: minor uploading images problem

    Originally posted by johnn

    What's the problem?...is this something to do with browser caching?
    Thanks in advance,
    John
    Yes, use php's header function,

    PHP Code:
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
    header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); 
                                                          
    // always modified
    header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
    header ("Pragma: no-cache"); 
    Paul

  4. #4
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just remember you have to send the header contents before any other output, for example instead of this

    PHP Code:
    <html>
    <?php 
    header 
    ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
    header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); 
                                                          
    // always modified
    header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
    header ("Pragma: no-cache");                          
    ?> ...
    you must write

    PHP Code:
    <?php 
    header 
    ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
    header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); 
                                                          
    // always modified
    header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
    header ("Pragma: no-cache");                          
    ?>
    <html> ...
    Paul

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I thought your problem sounded familiar, and after doing a little checking, I realized I had your exact same problem some time ago. I tried using the meta tags and the http headers listed above, but none of those worked for me. The only way I could get the image not to cache was to change an internet setting on my computer. I went to Tools/Internet Options and under the Temporary Internet Files heading, I clicked on Settings and under "Check for newer versions of stored pages:" the radio button "Automatically" was checked. I changed that and checked "Every visit to the page".

    I didn't consider that a solution because you can't count on the client to have that setting.
    Last edited by 7stud; Jun 16, 2001 at 21:42.

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Since you're trying to get your browser not to cache the image (not the document that contains it), you would have to send the fancy header commands supplied by others above along with the image itself. This would mean writing a PHP script with which to access the image file. The script would send the appropriate headers (along with a correct Content-Type header so the browser knows it's receiving an image), read the requested file, and then send the data to the browser as the content of the document.

    Pretty messy all up. In our current CMS, SitePoint simply relies on the user knoing to refresh the image preview page if he or she uploads a new image.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •