perlperl
asked on
upload file
in my cgi script, i have small part of html code, <input type = file> where user specifies file name
1) how can i upload user's .doc file and copy it on my server.
2) finally can i copy the same file on client machine
1) how can i upload user's .doc file and copy it on my server.
2) finally can i copy the same file on client machine
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1) something like:
use CGI:
my $q = new CGI;
my $bytesread = 0;
my $buffer = '';
open( FID, '>', "/path/to/file" ) or die "cannot open file";
while (my $more=read( $q->param{'file'}, $buffer, 8192 )) { $bytesread+=$more; print FID $buffer; }
use CGI:
my $q = new CGI;
my $bytesread = 0;
my $buffer = '';
open( FID, '>', "/path/to/file" ) or die "cannot open file";
while (my $more=read( $q->param{'file'}, $buffer, 8192 )) { $bytesread+=$more; print FID $buffer; }
ASKER
i tried
#!c:/perl/bin/Perl.exe
use CGI;
print "Content-type: text/html; charset=iso-8859-1\n\n";
$|=1;
my $q = new CGI;
my $bytesread = 0;
my $buffer = '';
$file = $q->param('upload_file');
print "$file";
open( FID, "> $file" ) or die "cannot open file";
while (my $more=read( $file, $buffer, 8192 ))
{
$bytesread+=$more;
print FID $buffer;
}
it creates file c:\\test.doc on server but it is not copying the contents of test.doc form clients machine to server.
the file is empty on server may be because its not going in whike loop
#!c:/perl/bin/Perl.exe
use CGI;
print "Content-type: text/html; charset=iso-8859-1\n\n";
$|=1;
my $q = new CGI;
my $bytesread = 0;
my $buffer = '';
$file = $q->param('upload_file');
print "$file";
open( FID, "> $file" ) or die "cannot open file";
while (my $more=read( $file, $buffer, 8192 ))
{
$bytesread+=$more;
print FID $buffer;
}
it creates file c:\\test.doc on server but it is not copying the contents of test.doc form clients machine to server.
the file is empty on server may be because its not going in whike loop
> open( FID, "> $file" )
dooh, that's dangereous, don't use it this way, hardcode the filename in your CGI.
> . is not copying the contents ..
you probably used the wrong variable for reading
dooh, that's dangereous, don't use it this way, hardcode the filename in your CGI.
> . is not copying the contents ..
you probably used the wrong variable for reading
ASKER
i tried this
#!c:/perl/bin/Perl.exe
use CGI;
print "Content-type: text/html; charset=iso-8859-1\n\n";
$|=1;
my $q = new CGI;
my $bytesread = 0;
my $buffer = '';
$file = "c:\\test.doc";
print "$file";
open( FID, "> $file" ) or die "cannot open file";
while (my $more=read( $file, $buffer, 8192 ))
{
$bytesread+=$more;
print FID $buffer;
}
still it is not reeading the file c:\test.doc from client....
#!c:/perl/bin/Perl.exe
use CGI;
print "Content-type: text/html; charset=iso-8859-1\n\n";
$|=1;
my $q = new CGI;
my $bytesread = 0;
my $buffer = '';
$file = "c:\\test.doc";
print "$file";
open( FID, "> $file" ) or die "cannot open file";
while (my $more=read( $file, $buffer, 8192 ))
{
$bytesread+=$more;
print FID $buffer;
}
still it is not reeading the file c:\test.doc from client....
ASKER
i also tried
while (my $more=read( $q->param('upload_file'), $buffer, 8192 ))
not working
while (my $more=read( $q->param('upload_file'), $buffer, 8192 ))
not working
ASKER
i lso tried
open( FID, "> $file" ) or die "cannot open file";
binmode (FID);
didn't work
is the header issue which cannot read local file on client's machine
open( FID, "> $file" ) or die "cannot open file";
binmode (FID);
didn't work
is the header issue which cannot read local file on client's machine
ASKER
Any comments?
Check that the form has enctype="multipart/form-da ta".
<form action="your/url" method="POST" enctype="multipart/form-da ta">
<form action="your/url" method="POST" enctype="multipart/form-da
ASKER