English 中文(简体)
image changed but appears the same in browser
原标题:
  • 时间:2009-11-09 15:38:06
  •  标签:
  • php
  • html

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one.

If i check my hard disk (i m working on local machine) i can see that the image HAS changed, but the HTML doesn t pick it up. Maybe it s a caching problem? How can I solve it?

thanks, Patrick

最佳回答

A common technique for ensuring images are never cached is to add the current time in miliseconds to the end of the image s url as a parameter. Your web server will ignore the parameter and serve the same image every time, but your browser (and any intermediate cache) will register a cache miss because the url for the image is different.

<a href= /images/someimage.png?d= <?php echo(date("U")); ?>  >
问题回答

If you re sure your HTML is pointing at the right file; Ctrl+F5?

Try to add a timestamp to the URL. This prevents most browsers from caching the images. Example: http://localhost/test.jpg?1257783872

Edit: Oh, Ryan has already given a similar answer. Sorry.

It could be that your ISP is using a caching proxy. Check the URL with BrowserShots to see if this is indeed the case. My back-up DSL is from a provider that does this to save bandwidth, its highly annoying. They also ignore every header telling them NOT to do it.

Are you sending the proper headers to prevent the browser from caching the image?

E.g.: http://www.badpenguin.org/php-howto-control-page-caching





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签