I have a form which users can use to upload images. Once the image is uploaded I use imagemagick to create thumbnails since the users image will be displayed on the page and I want it to load quickly. This all works fine. The problem is, I want the users to be able to rotate the image. I have written a function that basically calls exec() to rotate the image and save it via imagemagick. The function works fine, but since I am saving the file with the same name as the original, browsers seem to be using the cached version instead of the new one. If I force a non-cached refresh (ctrl-f5), I can see the rotated image. Anything else and it seems to use the cached version. You can upload an image and see what I'm talking about here.

I'm wondering if there is any way to force a non-cached page reload or if anyone has any other suggestions?

Thanks

    Hi,

    check if it works if you put the following header calls on top of the script (but behind any session_start()):

      header("Expires: " . gmdate("D, d M 1997 H:i:s") . " GMT");
      header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
      header("Cache-Control: no-cache, must-revalidate");
      header("Pragma: no-cache");
    
    

    Thomas

      Doesn't seem to be working. This is how I used it:

      include('products.php');
      header("Expires: " . gmdate("D, d M 1997 H:i:s") . " GMT");
      header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
      header("Cache-Control: no-cache, must-revalidate");
      header("Pragma: no-cache");
      

      This is the very top of the page. The first line in products.php is session_start().

        Do you get any warnings if you change the code to:

        include('products.php'); 
        error_reporting(E_ALL);
        ....
        ....
        

        Thomas

          Just a bunch of notices for some GET vars that aren't being passed a value. But that shouldn't matter.

          Example:
          Notice: Undefined index: option in /mnt/web_i/d36/s37/b022bb35/www/photoframeshop/products.php on line 122

          etc. etc....

            Ok,

            which setting does error_reporting in php.ini have ?

              Originally posted by tsinka
              Ok,

              which setting does error_reporting in php.ini have ?

              No Value 🙂

              And no, this is not local 🙁

                Ok, so I thought I'd post the header infor that is being used just in case it helps at all

                Date: Thu, 11 Nov 2004 20:30:01 GMT
                Server: Apache/1.3.26 (Unix) mod_perl/1.26
                Cache-Control: no-cache, must-revalidate
                Expires: Thu, 11 Nov 1997 20:30:01 GMT
                Pragma: no-cache
                X-Powered-By: PHP/4.3.6
                Set-Cookie: PHPSESSID=ca5291a092aab65a622636254ffdcac2; path=/
                Last-Modified: Thu, 11 Nov 2004 20:30:01 GMT
                Content-Type: text/html
                X-Cache: MISS from frameboston.com
                Connection: close
                Transfer-Encoding: chunked

                Btw,
                Firefox's Web Developer Extension++ 🙂

                  So I decided to just rename the thumbnail each time it gets rotated and it works 🙂 If anyone is interested, heres the code:

                  if($_GET['action'] == "rotate"){
                  	rotateThumb("uploads/thumbs/".$_SESSION['thumb'], $_GET['spin']);
                  	}
                  
                  function rotateThumb($name, $dir){
                  	$count = $_SESSION['thumbCount'];
                  	$newCount = $count + 1;
                  	$newName = "tn_".$newCount."_".$_SESSION['usrImage'];
                  	if ($dir == "left"){
                  		$rotate = "-90";
                  	}
                  	if ($dir == "right"){
                  		$rotate = "90";
                  	}
                  	if ($dir == "flip"){
                  		$rotate = "180";
                  	}
                  	exec ("/usr/local/nf/bin/convert -rotate ".$rotate." ".$name." uploads/thumbs/".$newName);
                  	$_SESSION['thumbCount']++;
                  	$_SESSION['thumb'] = $newName;
                  }
                  

                  Thanks for your help tsinka

                    Write a Reply...