Jump to content

Caching pics


Orio

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.
Link to comment
https://forums.phpfreaks.com/topic/18991-caching-pics/
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.
Link to comment
https://forums.phpfreaks.com/topic/18991-caching-pics/#findComment-82283
Share on other sites

Archived

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

×
×
  • Create New...

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.