By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,018 Members | 1,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,018 IT Pros & Developers. It's quick & easy.

file upload

P: n/a
Hi,

I used to have a web page with "<input type="file" name="FileName" size=20>
field to upload file to one of my Perl program in the server side. Now I
would like to use C# program to upload file to server but I don't want to
change my Perl program. Is there any way to use C# to upload file to Perl
program?

I know I can use Webclient.UploadFile(URL, "POST", filename) to upload file.
However, I believe I have to change something on my Perl program, but how?

Thanks.

Eric

My Web browser:

::::
<form method="POST" enctype="multipart/form-data"
action="../cgi-bin/fetchfile2.pl">
<p>
<input type="file" name="FileName" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"></p>
</form>
::::

My Perl program:

#!/usr/bin/perl

use CGI;
use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";
print "<html><body>";

$query = new CGI;

$filepath = $query->param ('FileName');

if ($filepath =~ /([^\/\\]+)$/)
{
$filename="$1";
}
else
{
$filename="$filepath";
}
# check the existence of the file
if (-e "../www/exchange/$filename")
{
print "A file with the same name exists, please rename your file.",
"<br>";
}
else
{
# open the file and load it

open (OUTFILE,">../www/exchange/$filename ");
binmode(OUTFILE);

my $buffer;

while (my $bytesread = read($filepath, $buffer, 1024))
{
print OUTFILE $buffer;
}
}
close (OUTFILE);
close ($filepath);

print "Your file ($filename) has been successfully uploaded.",
"<br>";
print "</body></html>";
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.