Hello,

        Here is what I currently do to accept file uploads from users via http:

#!/usr/bin/perl -w

use CGI;

$upload_dir = "/tmp";

$query = new CGI;

$filename = $query->param("fname");
$filename =~ s/.*[\/\\](.*)/$1/;
##
$upload_filehandle = $query->upload("fupload");

if ( $filename =~ m/match my requirements for naming/ ) {

        if ( -e "$upload_dir/$filename" ) {
                unlink $upload_dir/$filename;
        }

open UPLOADFILE, ">$upload_dir/$filename";

binmode UPLOADFILE;

while ( <$upload_filehandle> )
{
 print UPLOADFILE;
}

close UPLOADFILE;

$error = "Done\n";

} else {
        $error = "Invalid name\n";
}

print $query->header ( );
print <<END_HTML;

<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
</HEAD>

<BODY>

<P>Thanks for uploading!</P>
<P>$error

</BODY>
</HTML>

END_HTML

Also here is the html code used:

<HTML>
 <HEAD></HEAD>
 <BODY>
<FORM ACTION="/cgi-bin/filerecev.cgi" METHOD="post" ENCTYPE="multipart/form-data">
File to Upload: <INPUT TYPE="file" NAME="fupload">
Filename: <INPUT TYPE="text" NAME="fname">
 <br><br>
 <INPUT TYPE="submit" NAME="Submit" VALUE="OK">
 </FORM>
 </BODY>
</HTML>



I BioKid wrote:
One simple question -
I need to accept a file from the user and to store it as temp1.
then I need to give this file as an input of another program :
I wrote a script like this, but it is not working : Help ?

#!/usr/bin/perl -w
use CGI;
my $q = new CGI;
my $file = $q->param('file');
print $q->header();

# Reading file from user and writing to another file temp1
open (FOO, ">temp1");
while (<$file>)
       {
       print FOO $_;
       }
close FOO;

# internaly executing xxx program; taking temp1 as input
`/usr/bin/xxx temp1`;

#temp.xxx is output of usr/bin/xxx
@psa = `cat temp1.xxx`;

foreach $i(@psa)
{
       print "$i";
       print "<br>";
}


--
Michael Gale

Red Hat Certified Engineer
Network Administrator
Pason Systems Corp.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to