Reputation: 3777
This script snippet checks to see if a file exists in a directory and the builds a thumbnail. For some reason before the _1.jpg thumbnail an empty thumbnails is created with just a .jpg? Where is this happening, I can track it down?
Here is a tinyurl of the issue to see...best to test in IE as firefox automatically removes it: http://tinyurl.com/c6o2yts
<?
$image = "<br>";
$ListingRid = $row['ListingRid'];
$img_cnt = 1;
$image .= "<a href=/feeds/fmfl/rets_images/$ListingRid_1.jpg rel=enlargeimage::mouseover rev=loadarea><img src=/feeds/fmfl/rets_images/$ListingRid_1.jpg alt='' width='100' height='75' border='0' /></a> ";
for ($c=1;$c<10;$c++) {
$c_ext = $c;
if (file_exists("/var/www/vhosts/domain.com/httpdocs/feeds/fmfl/rets_images/{$ListingRid}_{$c_ext}.jpg"))
$image .= "<a href=/feeds/fmfl/rets_images/{$ListingRid}_{$c_ext}.jpg rel=enlargeimage::mouseover rev=loadarea><img src=/feeds/fmfl/rets_images/{$ListingRid}_{$c_ext}.jpg alt='' width='100' height='75' border='0' /></a> ";
else
$c=12;
$img_cnt++;
if ($img_cnt == 3) {
$image .= "<br>";
$img_cnt = 0;
}
}
?>
Upvotes: 0
Views: 128
Reputation: 41
The problem is here:
$image .= "<a href=/feeds/fmfl/rets_images/$ListingRid_1.jpg rel=enlargeimage::mouseover rev=loadarea><img src=/feeds/fmfl/rets_images/$ListingRid_1.jpg alt='' width='100' height='75' border='0' /></a> ";
And more specifically here:
$ListingRid_1.jpg
PHP allows underscores and integers in variable names. So while you want it to find $ListingRid . "_1"
, PHP interprets the variable's name as $ListingRid_1
, which does not exist.
You could use brackets, so that it becomes
$image .= "<a href=/feeds/fmfl/rets_images/{$ListingRid}_1.jpg rel=enlargeimage::mouseover rev=loadarea><img src=/feeds/fmfl/rets_images/{$ListingRid}_1.jpg alt='' width='100' height='75' border='0' /></a> ";
Also:
As an aside, a better way to exit a for
loop early is to use break
.
Upvotes: 1