Using sql or fopen to check for image?
Posted: Wed Jun 23, 2010 4:40 pm
Hi,
I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often.
To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail.
I have solved this using the following script:
My question is if it would be better to have a mysql database with information about the thumbnail and check if the image is there, instead of checking if the image file can be loaded? What is the most optimized approach if I start to gain traffic?
Thanks,
/Karl
I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often.
To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail.
I have solved this using the following script:
Code: Select all
$tImage = $_GET['i'];
$tURL = "upload/$tImage.jpg";
if(!($fp=fopen($tURL,"rb"))){
header("Location: thumb.jpg");
}else{
header("Location: upload/$tImage.jpg");
fclose($fp);
}Thanks,
/Karl