我使用PHP生成一封html电子邮件,它以图形形式向我的客户发送最新的统计数据。PHP每次发送具有相同镜像名称的统计数据时都会生成一个新镜像,以防止磁盘空间使用率过高。现在,我的问题是图像被缓存,从而向客户端显示旧图像而不是新图像。
我的html头文件如下所示。
"From: Test <test@test.com>\n"
// . "To: " . $contact . " <" . $email . ">\n"
. "To: myemail@test.com\n"
. "X-Confirm-Reading-To: test@test.com\n"
. "Disposition-Notification-To: test@test.com\n"
. "MIME-Version: 1.0\n"
. "Content-Type: multipart/mixed;"
. ' boundary="PAA08673.1018277622/www.test.com"'
. "\nSubject: Stats for $name\n\n"
. "This is a MIME-encapsulated message\n\n"
. "--PAA08673.1018277622/test@test.com"
. "\nContent-Type: text/html\n\n";
如何强制邮件从服务器下载最新生成的镜像?
发布于 2010-01-12 16:08:31
在URL中包含一些额外的内容,比如图表图像的时间戳
<img src="http://example.com/graphs/graph.png?t=1263283697">
这样,每当图像发生变化时,URL就会发生变化。这不会阻止用户代理缓存它看到的内容,因此即使在服务器更新之后,它仍然可能显示旧图像。
因此,如果您想要阻止用户代理实际缓存图像,那么编写一个脚本来返回带有一些头文件的图像,以防止缓存……
$file="graph.png";
$size=filesize($file);
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Length: $size");
header("Content-Type: image/png");
readfile($file);
发布于 2010-01-12 16:12:18
让文件名本身包含一个时间戳。因此,不是覆盖旧图像,而是首先删除它(从而确保它真的消失了),并用具有新图像名称的新图像替换它。
https://stackoverflow.com/questions/2047522
复制相似问题