Jump to content

Archived

This topic is now archived and is closed to further replies.

Orio

Caching pics

Recommended Posts

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.php
header("Cache-Control: max-age=604800, must-revalidate"); //one week caching
header("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.

Share this post


Link to post
Share on other sites
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 use
if(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.

Share this post


Link to post
Share on other sites
Can I ask why you would want to do this?  Most browsers automatically handle the cacheing of images for you.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.