in reply to Re: Re: Uploading files (total newbie needs help...)
in thread Uploading files (total newbie needs help...)

Here is a snippet of code that should do just as you ask - You will obviously need to cater it to your needs, but should give you a starting point:

#!/usr/bin/perl use CGI; use IO::File; use POSIX; use strict; my $cgi = CGI->new; # temporary file name is supplied by POSIX::tmpnam function my $buffer; my $tmpfile = POSIX::tmpnam; # loop through CGI handle and write new temporary file my $fh = IO::File->new(">".$tmpfile); print $fh $buffer while (read($cgi->param('inputfile'), $buffer, 1024) +); $fh->close; # retrieve file name from CGI file field parameter my $newfile = ($cgi->param('inputfile') =~ /^((?:.*[:\\\/])?)(.*)/s)[1 +]; # rename file unless file exists rename $tmpfile, $newfile unless -e $newfile; # return HTML headers and page data . . exit 0;

 

Ooohhh, Rob no beer function well without!