How to get the browser to cache images, with PHP?

后端 未结 5 1164
一整个雨季
一整个雨季 2020-11-27 16:42

I\'m totally new to how to cache images.

I output all images in a gallery with PHP, and want the images already shown, to be cached by the browser, so the PHP script

5条回答
  •  北海茫月
    2020-11-27 17:14

    You could store the generated images in a directory called "showImage" so that you would embed them like this

    
    

    Then you place a .htaccess file in the very same directory that will call showImage.php?id= in case the file does not exist, e.g.:

    
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^(.*)\.jpg$ showImage.php?id=$1 [QSA,L]
    
    

    Just read in your comment that you want to do client side caching: just set the caching-related HTTP headers according to http://www.mnot.net/cache_docs/

提交回复
热议问题