QUICK AND EASY JOB IN PERL: US$ 30.00
50% on delivery, 50% on final approval (milestones set on bid approval)
I have a perl script that saves a file on the server (from POSTed data) and then redirects to another page using "Location", sending arguments with GET.
I want 2 changes:
1. EXACTLY the same functionality, but using POST, not URL GET
2. fileName check in loop in directory '/maps/mapStore' to avoid overwriting
a. checks if no other file with same name
b. appends a counter to fileName ([login to view URL] -> fileName_1.php.. fileName_2.php..etc)
c. rechecks until OK to save
code is reproduced below:
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my $q = CGI->new();
my $Id_Area_Fazenda_Map_New = $q->param("Id_Area_Fazenda_Map_New");
my $filenamenew = $q->param("filenamenew");
my $data = $q->param("data");
my $target_dir = "/maps/tmp";
my $target_dir_final = "/maps/mapStore";
unless ( -d $target_dir ) {
mkdir $target_dir;
}
if ($data) {
$data =~ s{<br/>}{\n}gs;
my $fileName = $filenamenew."_".time().".txt";
my $fileExt = ".txt";
open my $fh, ">", $target_dir . "/" . $fileName or die $!;
print $fh $data;
close $fh;
my $URL = '[login to view URL]'.$fileName.'&fileExt='.$fileExt.'&Id_Area_Fazenda_Map_New='.$Id_Area_Fazenda_Map_New;
print "Location: $URL \n\n";
}