Home: Perl Programming Help: Beginner:
How can I check files upload with ext. "gif" or "zip" or "exe" ...



kiho
Deleted

Apr 27, 2000, 6:17 PM


Views: 1004
How can I check files upload with ext. "gif" or "zip" or "exe" ...

Hi all
Im looking for the code can check files user upload in my server are gif or zip or exe.
I want my user can upload "gif" or "jpg" only.
Thank you !!!


RayStreet
Deleted

Apr 27, 2000, 7:41 PM


Views: 1004
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ...

You can check the ending of a file name. For example, to find if a file ends in ".jpg" you can do:-

if ($filename =~ /.jpg$/) {
print "ok";
} else {
print "ono";
}


jumaru
Deleted

Apr 27, 2000, 7:47 PM


Views: 1004
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ...

Hi Ray

don't forget "\" before "."

$filename =~ /\.jpg$/;



[This message has been edited by jumaru (edited 04-27-2000).]


Cure
User

Apr 27, 2000, 7:59 PM


Views: 1004
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ...

Hi

Example.

if($file_upload =~ /(\.gif$)|(\.zip$)|(\.exe$)/i)
{
print 'not allowed to upload gif,zip or exe';
}
else {

print 'your stuff is being uploaded';
}


Cure



Rivotti
User

Apr 28, 2000, 4:19 AM


Views: 1004
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ...

I dont know if this helps but...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl
use CGI qw( :standart );

$file= new CGI->param('file_upload');
$file=~ m!([^/:\\]*)$!;
my $short_name = $1;

unless (!$file)
{ if ($short_name=~ /^\w+\.gif|\.jpg$/i)
{ # save file }

else
{ print "Incorrect file Format!" }
}
</pre><HR></BLOCKQUOTE>


RayStreet
Deleted

Apr 28, 2000, 12:18 PM


Views: 1004
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ...

Good spot jumaru - thanx

Ray