Hi,
i have thumbs provided from thumshots.org on my directory.
want i want is that these images can be cached on my server. why?
google images !! (i have another site with a lot o pics and there is coming a huge amaont of visitors tru google images.(50% of visitors))
there is a free php script on their site but i can 't manage it to work.
can someone have a look at this script?
i think that $url must be replaced somehow with <%url%> isn't it?PHP Code:/*
PHP Function to Locally store website images from http://www.thumshots.org
Code is free. No guarantees or warranties.
usage:
<img src="<? echo get_thumb("[LINK]"); ?>">
requires:
PHP 4 >= 4.3.0
*/
function get_thumb($url) {
//EDITABLE PARAMETERS
$local_thumb_dir="img/thumbs"; //Where Thumbnail images are stored locally
//Web Server needs to be able to write here
$days_to_keep=60; //How many days till check if new thumbnail
$return_img="/img/p.gif"; //To use if no thumbnail exists
//END EDITABLE
if(substr($url,0,4)!='http') $url='http://' . $url; //Make sure URL proper
$url=urlencode($url);
$fname=str_replace(array('%3A','%2F'),'_',$url);
$full_img_path=$_SERVER['DOCUMENT_ROOT'] . "/$local_thumb_dir/$fname.jpg";
if(file_exists($full_img_path)) {
//check age
$diff=(time() - filemtime($full_img_path))/60/60/24;
if ($diff > $days_to_keep) {
unlink($full_img_path);
} else {
$return_img="/$local_thumb_dir/$fname.jpg";
}
}
if(!file_exists($full_img_path)) {
//get from thumbshots.org
$buff=file_get_contents("http://open.thumbshots.org/image.pxf?url=$url");
if($buff!="") {
$fp=fopen($full_img_path, "wb");
fwrite($fp,$buff);
fclose($fp);
$return_img="/$local_thumb_dir/$fname.jpg";
}
}
return $return_img;
}
greetings peter


