httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: cgi put script?
Date Wed, 17 Jul 2002 20:56:57 GMT
Hi Owen,

Thanks for the info, it's really useful!  I like this "form" way of
uploading files.


Can you point me to any links for more documentation on the cgi scripts
(or related topics), for this way of using the post function on the server


 * * * *

Start at which is the official spec. Then look
for Table of contents -> forms -> the INPUT element -> type of control ->
file select... The spec is quite complicated so it will be better if you
follow this chain if discovery rather than parachuting into the section on
file select.

While I would encourage you to read the spec or a good HTML book (e.g.
O'Reilly's definitive guide - the koala book), it is really quite simple:

- in your form you do:

<form enctype="multipart/form-data" method="post" action="" >

<input type="file" name="banana">

then the rest of the form, including a submit button.

- when the user selects a file and submits, the file is read and the data
are transmitted to the server where can handle the parameters,
e.g. (I assume you are reasonably familiar with CGI programming in perl).

use CGI;
my $cgi = new CGI();
my $file = $cgi->param("banana");

The tricky thing is that if you reference $file as a scalar, you get the
name of the file - not the data. To get the data, you have to reference
$file as a filehandle. i.e.

print "$file"; # prints the name of the file

while (<$file>) {
  print "$_\n";

# prints all the lines in the file...

But, like I say, check the docs for details...


Owen Boyle.

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message