在php中重新上传具有相同文件名的图像时,如何清除浏览器缓存? [英] How to clear browser cache when re-uploading image with same filename, in php?

查看:79
本文介绍了在php中重新上传具有相同文件名的图像时,如何清除浏览器缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目清单,其中还包含一个图像缩略图。有时我需要更改缩略图图像,但文件名保持不变。有没有一种方法可以强迫浏览器下载新上传的图像,而不是从浏览器缓存中获取图像?

I have a listing of items, that also contains an image thumbnail. Sometimes I need to change the thumbnail image, but keep the filename the same. Is there a way to force the browser to download the newly uploaded image, instead of grabbing one from the browser cache?

当人们更新其头像时,这非常相关导致某些用户感到困惑,他们一直看到他们的旧头像,直到清除浏览器缓存或重新启动浏览器为止。

This is very pertinent when people update their avatars, which causes confusion for some users, who keep seeing their old avatar, until they clear the browser cache, or restart the browser.

推荐答案

在图像src的末尾添加一个唯一的数字

Append a unique number to the end of the image src

ie

<?php

echo "<img src=../thumbnail.jpg?" . time() . ">";

仅在用于更新头像的表单上执行此操作

do this only on the form for the updating avatar

为我工作

btw,这非常适合强制更新其他静态文件

btw, this works well for forcing updates of other static files

ie用于css文件的html是

i.e. html for css files is

<link rel="Stylesheet" href="../css/cssfile.css?<?= md5_file('cssfile.css'); ?>" /> 

这篇关于在php中重新上传具有相同文件名的图像时,如何清除浏览器缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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