2010-01-12 70 views
0

我使用PHP来生成一个HTML电子邮件,它发送我的客户最新的统计图表形式。 PHP每次使用相同的映像名称发送统计信息时都会生成一个新映像,以防止磁盘空间使用率过高。现在我的问题是图像被缓存,从而向客户端显示旧图像而不是新图像。PHP HTML生成的电子邮件缓存图像,从而显示旧图像

我的html标题看起来如下。

"From: Test <[email protected]>\n" 
     // . "To: " . $contact . " <" . $email . ">\n" 
     . "To: [email protected]\n" 
     . "X-Confirm-Reading-To: [email protected]\n" 
     . "Disposition-Notification-To: [email protected]\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/[email protected]" 
     . "\nContent-Type: text/html\n\n"; 

如何强制邮件从服务器下载最新生成的图像?

回答

3

包括一些在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); 
1

有文件名本身包括一个时间戳。因此,不是覆盖旧图像,而是先删除它(从而确保它确实消失),并用较新的图像名称替换为较新的图像。

相关问题