Orio Posted August 29, 2006 Share Posted August 29, 2006 Hello,Is this the right way to cache a picture, so the next time the picture is loaded it will come up faster?[code]<?php//This file is called picture.phpheader("Cache-Control: max-age=604800, must-revalidate"); //one week cachingheader("Content-type: image/jpg");include("image.jpg");?>[/code]In the page I want to displayed the cached pic called image.jpg write:<img src="picture.php">Or is there another way caching pics without having to create new caching files...?Thanks alot,Orio. Link to comment https://forums.phpfreaks.com/topic/18991-caching-pics/ Share on other sites More sharing options...
Orio Posted August 29, 2006 Author Share Posted August 29, 2006 Anyone?I thought of making a file called imageshower.php, and it'll look like this:[code]<?php//<validation> (if you have any offers to improove- be my guest)$formats=array("jpg","gif"); //the formats I useif(isset($_GET['pic']) || !is_file($_GET['pic'])) {die("No direct access.");}$explode=explode(".",$_GET['pic']);if(!in_array($explode[count($explode)-1], $formats) {die("No direct access.");}//</validation>//<cache>header("Cache-Control: max-age=604800, must-revalidate"); //one week caching//</cache>//<show image>header("Content-type: image/jpg");include("image.jpg");//</show image>?>[/code]Then for every pic I want to cache and show, I'll use <img src="imageshower.php?pic=pic.jpg"> for example.But I am not sure if this is right. And I have no way to check if it was cached or not...Thanks again,Orio. Link to comment https://forums.phpfreaks.com/topic/18991-caching-pics/#findComment-82283 Share on other sites More sharing options...
Orio Posted August 29, 2006 Author Share Posted August 29, 2006 Anyone? Please?Orio. Link to comment https://forums.phpfreaks.com/topic/18991-caching-pics/#findComment-82429 Share on other sites More sharing options...
ober Posted August 29, 2006 Share Posted August 29, 2006 Can I ask why you would want to do this? Most browsers automatically handle the cacheing of images for you. Link to comment https://forums.phpfreaks.com/topic/18991-caching-pics/#findComment-82446 Share on other sites More sharing options...
Orio Posted August 29, 2006 Author Share Posted August 29, 2006 Well I didnt know that :D Thanks for telling me that :)Either way, is this right? That's the way to cache pics? Or is it wrong/there's a better way doing it.Thx,Orio. Link to comment https://forums.phpfreaks.com/topic/18991-caching-pics/#findComment-82453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.