paulwhelan
asked on
force uploaded file to be certain name
i have two different questions here hence the large amt
of points on offer
the code below lets users upload files to my server
first adjusting the code below i would like
to make sure that no matter what the name of
the file is that users up load, it should always
be called "hello.txt"
second, in a seperate program i would like all uploaded
files to be called 1.txt, 2.txt etc.....
so that when someone uploads a file it is automatically
call 1.txt (if there are no files in the dir) or
2.txt (if 1.txt exists)......etc etc
thanks
paul
#!/usr/local/bin/perl
# upload.cgi
#print "Content-type: text/html\n\n";
use CGI;
use CGI::Carp 'fatalsToBrowser';
$myCGI = new CGI;
$outputPath = "/pathtodir/rubbish";
print $myCGI->header, $myCGI->start_html;
if (!$myCGI->param('fileName' )) {
print $myCGI->p("Sorry, your submission didn't include an upload.");
}
else {
($barefilename) = $myCGI->param('fileName') =~ /.*[:\/\\](.*)/;
$myFileStream = $myCGI->param('fileName');
binmode $myFileStream;
open (OUTFILE,">$outputPath/$ba refilename ") || die "Can't create outpu
t file: $!";
binmode OUTFILE;
while (<$myFileStream>) {
print OUTFILE;
}
close OUTFILE;
close $myFileStream;
print $myCGI->p("Thanks. We appreciate your upload of $barefilename.")
;
}
print $myCGI->end_html;
undef $myCGI;
of points on offer
the code below lets users upload files to my server
first adjusting the code below i would like
to make sure that no matter what the name of
the file is that users up load, it should always
be called "hello.txt"
second, in a seperate program i would like all uploaded
files to be called 1.txt, 2.txt etc.....
so that when someone uploads a file it is automatically
call 1.txt (if there are no files in the dir) or
2.txt (if 1.txt exists)......etc etc
thanks
paul
#!/usr/local/bin/perl
# upload.cgi
#print "Content-type: text/html\n\n";
use CGI;
use CGI::Carp 'fatalsToBrowser';
$myCGI = new CGI;
$outputPath = "/pathtodir/rubbish";
print $myCGI->header, $myCGI->start_html;
if (!$myCGI->param('fileName'
print $myCGI->p("Sorry, your submission didn't include an upload.");
}
else {
($barefilename) = $myCGI->param('fileName') =~ /.*[:\/\\](.*)/;
$myFileStream = $myCGI->param('fileName');
binmode $myFileStream;
open (OUTFILE,">$outputPath/$ba
t file: $!";
binmode OUTFILE;
while (<$myFileStream>) {
print OUTFILE;
}
close OUTFILE;
close $myFileStream;
print $myCGI->p("Thanks. We appreciate your upload of $barefilename.")
;
}
print $myCGI->end_html;
undef $myCGI;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.