开发者

Caching generated images with PHP

开发者 https://www.devze.com 2023-01-03 05:02 出处:网络
I am trying to cache images which have been generated. You create a image by accessing the file by resize.php?width=x&height=y.

I am trying to cache images which have been generated. You create a image by accessing the file by resize.php?width=x&height=y. If the image of that width and height does not exist I use imagemagick to create it. However if it does exist it is served to the visitor.

The !file_exists($name) check works fine so processing is not done when its not needed. However the images still take a while to load.

Is my approach of readfile incorrect o开发者_高级运维r have I set headers incorrectly?

if (!file_exists($name)) {
 //image processing here
}
header("Content-Type: image/png");
header("Expires: Sat, 25 Jul 2020 10:00:00 GMT");
readfile($name);

Thanks.


If i had to do this, i'd proccess the image if it does not exist save it in some web accessible folder. If the file exists just redirect to it header( 'Location: http://www.yoursite.com/path/to/existing/file.png' )

0

精彩评论

暂无评论...
验证码 换一张
取 消