I'm using the latest timthumb script to generate my post thumbnails and include them along with the excerpt. Though I only want the thumbnails to load if their files actually exist, otherwise I don't even want the image placeholder to load.
I'm going to be using this on a multi-user network, which is still in the early stages of development. And I want to test if the posts author has neglected to properly add the "thumb" custom field, which if they have, would normally return a 404 not found error.
So I've put the following code in my loop which first determines if the post has any images then using the file path for the first image listed in the post checks if the file exists.
<?php
$content = $post->post_content;
$searchimages = '~<img [^>]* />~';
preg_match_all($searchimages, $content, $pics);
$iNumberOfPics = count($pics[0]);
if($iNumberOfPics > 0){
$blogTemplate = get_bloginfo('template_directory');
$imgSrc = get_post_meta($post->ID, "thumb", $single = true);
$imgSrc = $blogTemplate . "/scripts/timthumb.php?src=" . $imgSrc . "&w=300&zc=1";
if(file_exists($imgSrc)){ ?>
<a href="<?php the_permalink(); ?>" class="thumb" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php echo $imgSrc; ?>" alt="<?php the_title(); ?>" /></a><?php
}
}
?>
I've tested the $imgSrc string that's outputted which is valid, it is an existing file though the my file_exists($imgSrc) function always returns false. I'm left wondering if the timthumb script is compatible with the file_exists() function?

file_exists()is a PHP function. TimThumb is an independent, third-party script that is unrelated to WordPress. – Chip Bennett Feb 6 '12 at 1:58