Skip to content

Instantly share code, notes, and snippets.

@karpstrucking
Last active August 29, 2015 14:06
Show Gist options
  • Save karpstrucking/8e86502c27eaa2182021 to your computer and use it in GitHub Desktop.
Save karpstrucking/8e86502c27eaa2182021 to your computer and use it in GitHub Desktop.
<?php
private function outputImage($filepath){
$info = UniteFunctionsRev::getPathInfo($filepath);
$ext = $info["extension"];
$filetime = filemtime($filepath);
$ext = strtolower($ext);
if($ext == "jpg")
$ext = "jpeg";
$allowed = array( "bmp", "gif", "jpeg", "png", "tga", "thm", "tif", "tiff" );
if ( ! in_array( $ext, $allowed ) )
exit();
$numExpires = 31536000; //one year
$strExpires = @date('D, d M Y H:i:s',time()+$numExpires);
$strModified = @date('D, d M Y H:i:s',$filetime);
$contents = file_get_contents($filepath);
$filesize = strlen($contents);
header("Last-Modified: $strModified GMT");
header("Expires: $strExpires GMT");
header("Cache-Control: public");
header("Content-Type: image/$ext");
header("Content-Length: $filesize");
echo $contents;
exit();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment