File Upload Script problem

 
Post new topic   Reply to topic    Aprelium Forum Index -> Perl
View previous topic :: View next topic  
Author Message
vastur
-


Joined: 15 Aug 2004
Posts: 1

PostPosted: Sat Sep 11, 2004 4:08 pm    Post subject: File Upload Script problem Reply with quote

Hello,

I made the following Perl Script for uploading files through the web-server:

---------------------------------------------------
use CGI;

my $cgi = new CGI;

my $dir = $cgi->param('dir');
my $file_handle = $cgi->param('file');
my $file_name = $cgi->param('file');

$file_name =~ s/.*[\/\\](.*)/$1/; # strip the remote path and keep the filename

open ( UPLOADFILE, ">..\\$dir\\$file_name" ) or die $!;

while(<$file_handle>) {
print UPLOADFILE;
}
close UPLOADFILE;

print $cgi->header();

print "File Uploaded: $dir\\$file_name";
---------------------------------------------------

"dir" & "file" are input parameters from a web-form.

The script works apparently well (outputs "File Uploaded...", creates the file in the mentioned directory, etc), but the data on the uploaded file is corrupted. It cannot be opened by any application and the size is *slightly* different (a few bytes more).

I'm using the Abyss web-server. Can this be a problem in the configuration of the server?
Or might it be an error in the script?

Thanks lots,

Vasco
Back to top View user's profile Send private message
hitam269
-


Joined: 10 Oct 2005
Posts: 4
Location: Franklin, TN

PostPosted: Mon Oct 10, 2005 5:06 am    Post subject: Reply with quote

After the line

Quote:
open ( UPLOADFILE, ">..\\$dir\\$file_name" ) or die $!;


you will need to add

Quote:
binmode UPLOADFILE;


That will transfer it in binary format rather than ascii format.

I've also got a question myself. If I were to use that script, how could I set it to allow only certain file types to be uploaded? For example, how could I set it to allow .JPG and .TXT files, but block .PL and .CGI files?
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Perl All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group