Gossamer Forum
Home : General : Perl Programming :

Checking if two files are available?

Quote Reply
Checking if two files are available?
Hi,

just a simple question for perl freaks:

I know how to check if a file exists on the server:

if (-e "/usr/local/etc/httpd/htdocs/pictures/$picture.jpg") {

How could i check, if the image exists as .jpg or as .gif?

Thanks for hints!

Quote Reply
Re: Checking if two files are available? In reply to
Why don't you do:


Code:
my $path = "/usr/local/etc/httpd/htdocs/pictures/";
my $ext;
my $found = 0;

if (-e "$path/$picture.jpg") {
$ext = "jpg";
$found = 1;
} elsif (-e "$path/$picture.gif") {
$ext = "gif";
$found = 1;
}

if ($found) {

# do something like open filepath: "$path/$picture.$ext"

}
Quote Reply
Re: Checking if two files are available? In reply to
Hope you don't mind me asking, but why would you need to find the extension?

Also how are you going to use the code to find the extension?.....I mean in what way will you use it?

Is the picture uploaded by a visitor or something and you want to check the extension?

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/