图片输出(image.php打开时允许用户下载图片)的发送应该使用哪些头部来将该图片的缓存时间设置为3天(而不是从用户端重新下载图片)?
我如何压缩图像并将其压缩,以及我应该发送哪些标头来告诉浏览器此图像已压缩?
谢谢你。
发布于 2011-01-10 00:27:57
如果您运行的是apache,那么最简单的压缩方法就是从htaccess级别启用deflate或gzip。如果没有,您可以将ob_gzhandler()
函数作为ob_start()
回调添加到文档的开头,如下所示:
<?php
if( !ob_start("ob_gzhandler") ) {
ob_start();
}
//Feel free to echo image data and whatnot, the callback deals with the headers, compatibility, and compression!
?>
注意,这需要zlib扩展。
您还可以add this function as the ob callback in the php.ini file或启用zlib.output_compression指令。
至于设置缓存,只需在输出文本之前添加此header()
调用:
<?php
header('Cache-Control: max-age='.(5184000 * 3).', must-revalidate'); //Cache should last for 3 days
?>
发布于 2011-01-10 00:38:13
这些头文件应该没问题
https://stackoverflow.com/questions/4640206
复制相似问题