How to browser cache image from php

六月ゝ 毕业季﹏ 提交于 2019-12-25 03:41:04

问题


I use virtuemart. There are a lot of images about the products. But this images come from a php file(imgtag.php), so I can't force the browser with this code to take the product images to the cache:

<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|ttf|eot|swf)$">
   Header set Cache-Control "max-age=2592000"
</FilesMatch>

Example for product image URL:

http://www.myshop.com/components/com_virtuemart/show_image_in_imgtag.php?filename=be6160cc3ede6b58d13f4adaa61f49f7.jpg&newxsize=120&newysize=120&fileout=

How can I do this?


回答1:


You could modify your imgtag.php file, so it sends that header, using the PHP header() function :

header('Cache-Control: max-age=2592000');

Note : setting headers must be done before any output.



来源:https://stackoverflow.com/questions/5316829/how-to-browser-cache-image-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!