#!/usr/bin/perl
#
# simple_uploader.pl -- A simple perl cgi script which
#	will save the uploaded file into the server.
#
# Last modified: 29th.Mar.1999
#
# Simon Tneoh Chee-Boon   tneohcb@pc.jaring.my
# 
# Copyright (c) 1998,1999 Simon Tneoh Chee-Boon. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
use Carp;
use strict;
use CGI_LIB;

#
# We create the CGI_LIB object, i.e. we process the submitted
# data.
#
my($cgi) = new CGI_LIB;

#
# We save the uploaded file to a filename that we set.
# You can also get the filename from the CGI_LIB object:
# $cgi->{'uploadedFile'}->{'filename'}
# (Assume that we are using "uploadedFile" as the name for the
# "file" input tag.)
# But make sure you check the filename before you use it,
# because this might create a security hole.
#
my($filename) = "/path/of/file";
open(FILE, ">$filename") || confess "Fail to create file: $!";
# Uncomment the following line if you are NT user and try to 
# save a binary file.
# binmode(FILE);
print FILE $cgi->{'uploadedFile'}->{'contents'};
close(FILE);

#
# We print the thank you message.
#
print "Content-Type: text/html\n\n";
print <<__END__HTML__;
<html>
<head><title>Thank You</title></head>
<body>
<h2>Thank You</h2>
File has been uploaded successfully.
</body>
</html>
__END__HTML__
exit 0;
