lewisstevens1 Posted January 21, 2013 Share Posted January 21, 2013 Hello guys, hope you can help. I have a PHP script where users can upload and crop their profile photo, there's one problem though.. Sometimes after their account profile photo has been uploaded, it displays in the crop box, although when users actually go to crop sometimes they don't see an update and sometimes they do. I tried adding a refresh button but that doesn't seem to do it. The only way they can view the update is by pressing F5. Ive tried adding: <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> in the html. I even added: header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); in the PHP. What can i do? Many thanks Lewis Stevens Quote Link to comment Share on other sites More sharing options...
BagoZonde Posted January 21, 2013 Share Posted January 21, 2013 (edited) Is that what you asked for: print '<img src="/' . $file . '?' . date('YmdHis') . '" alt=" ' . $alt . ' ">'; This trick will force browsers to overload image as there will be no one with given path in cache for sure. Edited January 21, 2013 by BagoZonde Quote Link to comment Share on other sites More sharing options...
lewisstevens1 Posted January 21, 2013 Author Share Posted January 21, 2013 So that will output something like <img src='myfile.jpg?20120121143700' alt='a number'/> will that just do the same as putting a ? in the url? Quote Link to comment Share on other sites More sharing options...
BagoZonde Posted January 21, 2013 Share Posted January 21, 2013 (edited) This will do nothing more than trick browser to read file once again because there will be no file like "myfile.jpg?20120121143700" in cache. You'll see updated image only. Edited January 21, 2013 by BagoZonde Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 21, 2013 Share Posted January 21, 2013 You need the timestamp, not just the ?. Quote Link to comment Share on other sites More sharing options...
BagoZonde Posted January 21, 2013 Share Posted January 21, 2013 (edited) You need the timestamp, not just the ?. That's right. lewisstevens1, you need to change filename every time so it's cool to change part after query sign. BTW. I'm using date('YmdHis') instead of timestamp() as I'm thinking in blind-assembler-way for 1MHz machines: OPTIMIZE . But sincerely this difference wasn't tested yet, haha . Edited January 21, 2013 by BagoZonde Quote Link to comment Share on other sites More sharing options...
lewisstevens1 Posted January 21, 2013 Author Share Posted January 21, 2013 Oooh it actually works! Thankyou guys... ive never even thought of doing something like that... You guys are awesome! 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.