用php代码可以清除浏览器的缓存? [英] Possible to clear cache of browser with php code?

查看:241
本文介绍了用php代码可以清除浏览器的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



用户可能会选择一个文件,并以特定的文件名上传文件,如果用户感到后悔,选择该文件文件他们可以点击文件输入并上传另一个文件,但文件名是相同的,所以浏览器缓存上传的第一个图像。而不是第二张图片,浏览器会显示第一张图片,即使它是上传的另一张图片。



有点难以解释...



我该如何解决这个问题?

谢谢

解决方案 div>

禁用Web服务器中的图像缓存或将随机查询字符串追加到图像的 src 中。



通过随机查询字符串,我的意思是您将每个请求上发生更改的内容追加到图像的URL。
就像这样:

 < img src =http://www.example.com/image。 jpg?<?php echo Time()?> /> 

Time()返回当前的TIMESTAMP,并且每次请求都会改变,所以URL总是不同,从而迫使浏览器每次下载图像。

I have a image upload tool written in php.

Users may chose a file, and it gets uploaded with a certain filename, then if the user regrets chosing that file they may click the file-input and upload another file instead, BUT THE FILENAME IS THE SAME, so the browser caches the first image uploaded. And instead of the second image the browsers display the first one instead, even though it's another image uploaded.

Kindof hard to explain...

How can I solve this?

Thanks

解决方案

Either disable caching of images in your web server or append a random query string to the src of your image.

By "random query string" I mean that you append something that changes on every request to the URL of the image. Something like this:

<img src="http://www.example.com/image.jpg?<?php echo Time () ?>" />

Time () returns the current TIMESTAMP and will change on every request, and so the URL will always be different and thus forcing the browser to download the image every time.

这篇关于用php代码可以清除浏览器的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆