我正在开发一个Web应用程序来转换用户上传的图像。 当用户更改图像时,它将在服务器中以其他名称保存,并再次提供给客户端,如img标记。 回到上一张图片时遇到问题。删除实际图像,新图像是之前的图像。但是当用户再次更改时,显示的图像不是新图像,而是返回之前删除的图像。但是,显示的图像不存在。我猜它是由浏览器缓存的,但不知道如何防止这种情况。
示例:
$image1 = imagefirst.jpg
$image2 = imagechanged.jpg
//Going back:
$image3 = imagefirst.jpg
//imagechanged.jpg is deleted
//change again the image
$image4 = imagechanged.jpg
//serve to the client
<img src="imagefirst.jpg">
//the image shown isn't the new one saved in the server, but the image deleted previously.
答案 0 :(得分:2)
只需在图像的src
属性中添加随机数:
<!-- 759293475438 generated randomly each time -->
<img src='imagefirst.jpg?759293475438'/>
- 为此,您可以在PHP中使用mt_rand()。
答案 1 :(得分:2)