Select Page

ImageCachingTest


ImageCachingTest

TESTING Image Caching


“;
echo $image_url;
echo “

“;

//replace with your cache directory
//$image_path = ‘path/to/cache/dir/’;
$image_path = ‘/home/dcline/seasonalgo/’;
//get the name of the file
$exploded_image_url = explode(“/”,$image_url);
$image_filename = end($exploded_image_url);
$exploded_image_filename = explode(“.”,$image_filename);
$extension = end($exploded_image_filename);
//make sure its an image
if($extension==”gif”||$extension==”jpg”||$extension==”png”){
//get the remote image
$image_to_fetch = file_get_contents($image_url);
//save it
$local_image_file = fopen($image_path.$image_filename, ‘w+’);

echo “
A—
“;
echo $local_image_file;
echo “
0—
“;

chmod($image_path.$image_filename,0755);
echo “
1—
“;
fwrite($local_image_file, $image_to_fetch);
echo “
2—
“;
fclose($local_image_file);

echo $image_path.$image_filename;
echo “
3—
“;
echo ““;
echo “
4—
“;
}
}

function GuaranteeCachedImage($contractName, $targetImageUrl){
// Check to see if image exists on disk
// If it exists, return URL to the cached image
// Else
// Fetch the image and cache it
// Then return the URL to the cached image

// Local storage occurs in: /home/dcline/seasonalgo/
$webStorage = “/seasonalgo/”;
$webImageLocation = $webStorage.$contractName.”Chart.png”;

$localStorage = “/home/dcline/seasonalgo/”;
$localImageLocation = $localStorage.$contractName.”Chart.png”;

if (file_exists($localImageLocation))
return $webImageLocation;

//get the remote image
$targetImageContents = file_get_contents($targetImageUrl);

//save it
$localImageFile = fopen($localImageLocation, ‘w+’);
chmod($localImageLocation, 0755);
fwrite($localImageFile, $targetImageContents);
fclose($localImageFile);

// return web path to this saved image
return $webImageLocation;
}

?>

CCSTrade
Share This