Forum Moderators: coopster
This is the script i have at the moment, but, it keeps re-generating the thumbs each time the script is run. I find out by the last modified date/time on the thumbnail files in testing, and it always says the time that i ran the page. The 'already done' echo bit isnt needed for the final script, but in there so i know that the else statement is used instead of the thumbs been generated, and of course, the 'already done' statement never appears.
Ive tried numerous attempts from scripts on php.net and a quick google search, but they either do the same or throw up errors...
$dir = "thumbs/";
$count = 0;
if(is_dir($dir)) {
if($handle = opendir($dir)) {
while(($file = readdir($handle)) !== false) {
$count++;
}
closedir($handle);
}
}
if ($count == 0) {
include ("thumbnail_generator.php");
}
else {
echo "already done";
}
So i dont think its reading the folder, which definatly exists, or counting the files correctly.
$thumbsDirectory = "thumbs";
$count = 0;
if(is_dir($thumbsDirectory)) {
if($handle = opendir($thumbsDirectory)) {
while(($file = readdir($handle)) !== false) {
$count++;
}
closedir($handle);
}
}
echo $count;
By else's with echos I meant check for the false of each of your conditions, not remove the single else that you had.
$thumbsDirectory = "path/to/my/webdocuments/thumbs";
$count = 0;
if(is_dir($thumbsDirectory)) {
if($handle = opendir($thumbsDirectory)) {
while(($file = readdir($handle)) !== false) {
$count++;
} // endwhile getting files
closedir($handle);
} // endIf opened directory
else echo "opendir() failed.";
} // endIf is directory
else echo "Directory doesn't exist.";
echo $count;
In order to fix a problem you have to figure out exactly where the problem is occurring - you have three things going on up there so you need to narrow it down. Without inline debugging, about the only way is to echo/dump variables and function results all over the place, then remove them and design more elegant ways of handling/reporting/recovering from all remaining possible error conditions.
Just this morning I copied an app from one web site to another and it burped in a particular section - the complaint was invalid argument to implode. Adding echos revealed that it was actually a missing field in a database table 20+ lines earlier. If I hadn't echoed the sql that the script compiled I'd probably still be scratching my head...