Well, as given in the title, I want to cache the resource generated by my php script on the user's browser. I want to do so because I want to serve thumbnail images for some images from the server side dynamically. I have this .htaccess
file with these contents in it.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?image_id=$1 [QSA,L]
And index.php file contains these codes.
<?php
header('Last-Modified: ' .gmdate('D, d M Y H:i:s',time()-3600) . ' GMT');
$image_id=$_GET['image_id'];
$chunk= explode("/", $image_id);
$destination_height=$chunk[0];
$destination_width=$chunk[1];
$image=$chunk[2];
if(file_exists($image))
{
$extension=explode(".",$image);
$extension=end($extension);
switch ($extension) {
case "jpg":
$source_image= imagecreatefromjpeg($image);
break;
case "jpeg":
$source_image= imagecreatefromjpeg($image);
break;
case "gif":
$source_image= imagecreatefromgif($image);
break;
case "png":
$source_image= imagecreatefrompng($image);
break;
default:
break;
}
$source_height = imagesy($source_image);
$source_width = imagesx($source_image);
if($destination_height=="full")
{
$destination_height=$source_height;
}
if($destination_width=="full")
{
$destination_width=$source_width;
}
$destination_image= imagecreatetruecolor($destination_width, $destination_height);
$dst_x=0;
$dst_y=0;
$src_x=0;
$src_y=0;
imagecopyresized($destination_image,$source_image,$dst_x,$dst_y,$src_x,$src_y,$destination_width,$destination_height,$source_width,$source_height);
switch ($extension) {
case "jpg":
imagejpeg($destination_image);
header("content-type:image/jpeg");
break;
case "jpeg":
header("content-type:image/jpeg");
imagejpeg($destination_image);
break;
case "gif":
header("content-type:image/gif");
imagegif($destination_image);
break;
case "png":
header("content-type:image/png");
imagepng($destination_image);
break;
default:
break;
}
}
?>
Even after this when I go to developer mode and see the network tab on google chrome, the status information is : 200 OK
What can be done to cache all the images generated by this script? Because for a particular url, in this implementation, the content is never changed, so I want to cache the images.
Any sort of ideas will be appreciated. Thanks.