CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

Post #1 of 6 (638 views)
How can I check files upload with ext. "gif" or "zip" or "exe" ... Can't Post

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

Post #2 of 6 (638 views)
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ... [In reply to] Can't Post

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

Post #3 of 6 (638 views)
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ... [In reply to] Can't Post

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

Post #4 of 6 (638 views)
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ... [In reply to] Can't Post

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

Post #5 of 6 (638 views)
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ... [In reply to] Can't Post

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

Post #6 of 6 (638 views)
Re: How can I check files upload with ext. "gif" or "zip" or "exe" ... [In reply to] Can't Post

Good spot jumaru - thanx

Ray

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives