httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From greeni...@xsmail.com
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.

Question-

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
side?

Steve

 * * * *

Start at http://www.w3.org/TR/html4/ 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="my_prog.pl" >

<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 my_prog.pl 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...

Rgds,

Owen Boyle.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org







---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message