6
Hi zyspec,
No worries. What I have now is working. Having said that, 'working' doesn't mean 'correctly coded'. By all logic, your code should have functioned and it's beyond my extremely limited php vocabulary as to why it's not. It's not an extremely pressing issue, though, so definitely don't lose any sleep. TDM, though, will definitely benefit from your code as this feature is far more effective than simply displaying a random shots image with no link to the actual entry.
I ended up reworking the problem of the blank string by forcing a default in the event a string returns null. So far, this is working 100% of the time without error. There were no other file formats in the directory, though, which is why the return of a null string is a mystery. I classified the problem as 'coding error' and handled it as best as a CG artist could.
I also fixed a redundancy issue. The error-catching is now done prior to the image and filename conversions.
if ($handle = opendir('uploads/TDMDownloads/images/shots/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file = substr($file, 0 , -4);
$narray[$i]=$file;
$i++;
}
$extension = ".jpg";
$j = rand(0, $i-1);
$filename = "$narray[$j]";
if ($filename=="") {
$filename = "cid68lid2";
}
$image = "$filename$extension";
$filename = str_replace('cid', 'cid=', $filename);
$filename = str_replace('lid', '&lid=', $filename);
}
echo "n";
closedir($handle);
}
?>
Again, here's how the block is setup:
<div align="left" style="verticle-align:top;"><Iframe src="http://coastalgfx.com/randcgi.php" width="172" height="172" frameborder="0" scrolling="no" marginheight="0" marginwidth="0">Iframe>div>
<div align="center"><Iframe src="http://coastalgfx.com/dl_count.php" width="164" height="27" frameborder="0" scrolling="no">Iframe>div>
Thanks for the reply and I look forward to your input.
Is this the code change you're suggesting:
if ($handle = opendir('uploads/TDMDownloads/images/shots/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file = substr($file, 0 , -4);
$narray[$i]=$file;
$i++;
}
}
$extension = ".jpg";
$j = rand(0, $i-1);
$filename = "$narray[$j]";
if ($filename=="") {
$filename = "cid68lid2";
}
$image = "$filename$extension";
$filename = str_replace('cid', 'cid=', $filename);
$filename = str_replace('lid', '&lid=', $filename);
echo "n";
closedir($handle);
}
?>