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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.