Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Software error: Can't cd to : HELP!

Status
Not open for further replies.

calypso13

Technical User
Nov 5, 2004
21
0
0
US
Am a perl newbie.
when I try displaying this script in a browser, I get this error "Can't cd to : " .
However, this script works in command line.

For now, I would like to display the list of files in a browser.
Also, how do I create a form to search these images with?
thanks

#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/my $image;
my @files;
my $files = qr/^\d{6,6}.*\.jpg?$/i;

@files = File::Find::Rule->file
->name($files)
->in($imageDir);
print $q->header();
$q->start_html("Images in $imageDir");

foreach my $image (@files){
if($image){
print <<HTML;
<a href="$image">$image</a>
HTML
}
else{
print <<HTML;
sorry, $image does not exist
HTML
}
}
 
Not quite sure what the problem might be, but I suggest a couple of pointers.

1) in the end foreach, the test should really be to see whether the file exists. Otherwise the else is redundant (except in very extreme edge cases) and should never get printed.

2) the mapping of $image into a href will work for you locally, but no-one else.

Try:

Code:
foreach my $image (@files){
	if(-f $image){

		my $webimage = $image;
#		$webimage =~ s!/var/www![URL unfurl="true"]http://$ENV{'HTTP_HOST'}!;[/URL]
									# absolute path
		$webimage =~ s!/var/[URL unfurl="true"]www!!;[/URL]	# relative path

print <<HTML;
<a href="$webimage">$image</a>
HTML

	} else{

print <<HTML;
sorry, $image does not exist
HTML

	}
}

If the error is while File::Find::Rule is working, then there is the likelihood that the webuser doesn't have access to a subdirectory of /var/
Barbie
Leader of Birmingham Perl Mongers
 
The webuser has access to /var/ I can access it from my browser right now. And I sliced out /var/www/ from the url so its displays but it still doesnt work in the browser. Could there be another explanation for this error. I checked to see if the subdirectory exists and it says it does.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top