views:

176

answers:

5

I am trying to upload a new picture in my webpage, but in the browser it is showing the old picture. When i check in the folder new image is being saved but it is not showing in the page. I tried to refresh but it is not helping me, shut down the browser still the same, tested in different browser still old image, Need help what can i do now. Im uploading picture using php coding with ajax.

A: 

try renaming the picture in a different name

liza
+2  A: 

Try pressing Ctrl-F5 in the browser. This should force a refresh of the cache.

If you are using a script to generate your pages, you could pass the no-cache http flag in the output headers for the image. The header would be:

Cache-control: no-cache

Edit: I see you are using php, is there any chance you could 'echo' the image in a separate php page? Then you could use the line

header("Cache-control: no-cache");
George Edison
A: 

Try clearing your cache THEN refresh the browser. There is the possibility that you are still seeing the cached image, despite the contents changing on the server.

Mr-sk
+1  A: 

Are you updating the src attribute of the image tag with the new filename? o.O

robertbasic
yes, retrieving filename from db andd then putting into src.eg: src="<?php echo "/upload/profile/thumb/".$rowdata['id'] ?>
jazzrai
+2  A: 

I'm not sure I fully understand what you are trying to accomplish, but obviously there is some caching of sorts going on. If you've uploaded an image, with the same file name, and it refuses to refresh, or you simply don't want to depend on a refresh of the users cache, a simple solution would be to append a random number to the end of your image src after a question-mark. i.e.

<img src="/images/face.png?1234324">

...which will essentially make the browser believe the image is a new image (which it is), and thwart it's attempt to use the browsers cache.

George
Nice, but unfortunately ugly. Too bad browsers ignore standard HTTP headers.
George Edison