Dakshina`s Blog

My views..
Thursday Nov 30, 2006

CGI/Perl script for uploading files

Here's a small perl script that I have used for uplaoding files to a webserver.

The location can be changed .Rt now it saves the files to /tmp/upload1

#!/usr/bin/perl
use CGI ;
my $query = new CGI;
print $query->header ( );
# Expects the client to sends the name of the file to be uploaded in an input field "file"


my $filename=$query->param("file");
my $fpath1="/tmp/upload1/$filename";

open (UPLOADFILE,">$fpath1") || die "Cannot open file";

$filename =~ s/.*[\/\\](.*)/$1/;
my $upload_filehandle = $query->upload("file");

my $buf;
while (read($upload_filehandle,$buf,1024)) {
   print UPLOADFILE $buf;
}

close UPLOADFILE;

#This has been tested on Solaris only

# Can be used to transfer binary files also

#For WINDOWS the BINMODE option may be needed 

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed

Archives
Links
Referrers