Question : Retrieving POST information from CGI script and updating database

This question has been somewhat answered before, though vaguely, so I'm giving it a try.

Basically, I have the attached code in a CGI uploading script. It uses this bit of code to POST the information to a PHP file that I designate. I need to know how to write a PHP file that will take ONLY the original filename and its extension (I believe that would be $filenames[$_]), connect to a database, attach the filename to a URL (i.e. http://www.mydomain.net/uploads/[filename.ext]), and throw that URL into a field in one of the tables in my database.

It's not quite as complicated as it might seem. I just need to know how to write a PHP file that will get the original filename from this CGI script.

Thanks very much.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
### Sending data with POST request if required
my $url_post = $cg->param('url_post');
$url_post ||= $c->{url_post};
if($url_post)
{
   my ($str,@har);
   for (0..$#fileslots)
   {
      push @har, { name=>"$fileslots[$_]_original",'value'=>$filenames[$_] };
      push @har, { name=>"$fileslots[$_]",         'value'=>$filenames2[$_] };
      push @har, { name=>"$fileslots[$_]_status",  'value'=>$file_status[$_] };
   }
   for my $k (@params)
   {
      my @arr = $cg->param($k);
      for my $p (@arr)
      {
         next if ref $p eq 'Fh'; #&& $p !~ /\.$c->{ext_allowed}$/i; # Skip unallowed files
         $p =~ s/.*\\([^\\]*)$/$1/;
         push @har, { name=>$k, value=>$p };
      }
   }
 
   push @har, { name=>'target_dir', value=>$c->{target_dir} };
 
   print"";
   print"" for @har;
   print"";
   exit;
}
Open in New Window Select All

Answer : Retrieving POST information from CGI script and updating database

I know nothing about Perl, but the PHP side should be pretty straightforward.

All POST data can be found in the superglobal $_POST.  If your form has a control named "filename", then $_POST['filename'] will hold that data in PHP.

The rest is just running a query.
1:
2:
3:
4:
5:
6:
7:
8:
9:

Open in New Window Select All
Random Solutions  
 
programming4us programming4us