#look for files in $DIR sub collect_files { opendir(DIR, "$DIR"); while (defined(my $file = readdir(DIR))) { if ( ! -d $file ) { &check_mime_type($file); } } closedir(DIR); } #collect files, create thumbnails and pass list of images back to cgi +output sub collect_thumbs { &collect_files; my @thumbs; opendir(DIR, "$DIR/thumbs"); while (defined(my $file = readdir(DIR))) { if ( ! -d $file ) { push(@thumbs, $file); } } closedir(DIR); return @thumbs; }
readdir gives you a file name from the directory $DIR (or "$DIR/thumbs") but you are not testing the file in that directory ( ! -d $file ), you are testing it in the current directory. You need to prepend the directory name to the file name to test the correct file.
You should also always verify that open, opendir and unlink worked correctly.
See also: What's wrong with always quoting "$vars"?
In reply to Re: Thumbnail autoindex
by jwkrahn
in thread Thumbnail autoindex
by ScOut3R
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |