#!/usr/local/bin/perl
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser); my $tmpDir = $ENV{"PATH_TRANSLATED"}; $tmpDir =~ m|(.*)\\cgi-bin|; my $siteBase = $1;
my $UploadDirectory = "$siteBase\\upload"; # next line for Windows/IIS sites only (temporary directory where web-server also needs write access)
$TempFile::TMPDIRECTORY="$siteBase\\tmp";;
my $query = new CGI; my $file = $query->param('file'); # let's extract the filename
$file=~m/^.*(\\|\/)(.*)/; #separate path and filename
my $fileName = $2; # the matching part in the second pair of brackets
open(LOCALFILE, ">$UploadDirectory\\$fileName") or die $!; # exit if you cannot create local file while(<$file>)
{ print LOCALFILE $_; } close LOCALFILE; close $file;
print $query->header(); print "<html><body><h1>The file '$file' has been uploaded ... thank you.</h1></body></html>\n"; |