Nygganh Posted November 18, 2013 Share Posted November 18, 2013 (edited) Hi, I have a image upload script and a image viewer. The image viewer works something like this: http://www.website.com/image/id_of_image/width/height That will cache and render an image with headers looking something like this: header('Content-Type: ' . $content_type); header('Content-Length: ' . strlen($image_data)); header('Cache-Control: max-age=' . Date::HOUR . ', public, must-revalidate'); header('Expires: ' . gmdate('D, d M Y H:i:s', (isset($_GET['clear_cache']) ? NOW - Date::YEAR : NOW + Date::HOUR)) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->last_modified_time) . ' GMT'); header('ETag: ' . $etag); Everything's working great, expect for when I'm uploading a new image over an existing one (with same filename), I automatically refresh the page after the upload but the image doesn't get refreshed until I manually refresh the page. I have tried to make a CURL request to the image right after the image is uploaded, but that doesn't seem to trigger the cache to get renewed. It looks something like this: $ch = curl_init('http://www.website.com/image/id_of_image/width/height?clear_cache=1'); curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_exec($ch); The CURL request is made correctly and I can see the request in my access log. In my CURL request, I pass ?clear_cache=1. This trick, to change the Expires-header on the CURL request only seems to work in Chrome, but that's because Chrome doesn't give me the "If-None-Match" and is not cached correctly. But maybe that's on the right track? What is a good approach here? I don't want to add a timestamp to my image URL:s since that would trigger the images to never cache. Thanks! Edited November 18, 2013 by Nygganh Quote Link to comment Share on other sites More sharing options...
Solution Nygganh Posted November 19, 2013 Author Solution Share Posted November 19, 2013 I resolved this by my own by adding the timestamp to the URL ONLY after users changes their avatars. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.