calypso has asked for the wisdom of the Perl Monks concerning the following question:

when I try displaying this script in a browser, I get this error "Can't cd to : "
However, the script works fine in command line. The subdirectory /var/www/images does exist. I can access it from my browser. The permissions are fine. Does anyone have an idea why this error occurs? Am fairly new to PERL.
#find.pl #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use strict; use CGI; use warnings; use Cwd; use File::Find::Rule; my $q = new CGI; my $imageDir = '/var/www/images/'; my $image; my @files; my $files = qr/^\d{6,6}.*\.jpg?$/i; #my $image = $q->param('image'); @files = File::Find::Rule->file ->name($files) ->in($imageDir); print $q->header(); $q->start_html("Images in $imageDir"); foreach my $image (@files){ if( $image){ my $imageFile = $image; $imageFile =~ s/\/var\/www//; print <<HTML; <a href="$imageFile">$imageFile</a><br> <img src="$imageFile"> HTML } else{ print <<HTML; sorry, $imageFile does not exist HTML } } print $q->end_html;

Replies are listed 'Best First'.
Re: software error - Can't cd to : HELP !!
by cowboy (Friar) on Feb 04, 2005 at 20:03 UTC
    Often times webservers, or scripts, will be run in some sort of jail/chroot environment, or other security sandbox. You might try something like the following, to see what is going on.
    #!/usr/bin/perl use CGI; use Cwd; my $q = new CGI; print $q->header(); print "<pre>\n"; printf("cwd: %s\n", getcwd); printf("/var/www/images: %s\n", -d "/var/www/images" ? 'is a directory +' : 'is not a directory'); printf("/var/www/images: %s\n", -r "/var/www/images" ? 'readable' : 'n +ot readable'); printf("</pre>");
    This won't solve your problem, but might point you in the right direction.
      yeah..I checked the directory and its fine and readable. i will keep digging into it, meanwhile if anyone has a help solution or direction, please please..help me out.
Re: software error - Can't cd to : HELP !!
by VSarkiss (Monsignor) on Feb 04, 2005 at 22:10 UTC
      I got it to work with File::Find::Rule, I just had to chdir. For some reason the rule wasnt doing it. thanks for the tips.