##
#!/usr/bin/perl
use warnings;
use strict;
use Socket;
my $url = "http://zentara.zentara.net/~zentara/cgi-bin/up1.cgi";
my $upfile = shift || 'ztest.png';
my $host = "zentara.zentara.net";
$| = 1;
my $start = times;
my ( $iaddr, $paddr, $proto );
$iaddr = inet_aton($host);
#$iaddr = ( gethostbyname($host) )[4];
$paddr = sockaddr_in( 80, $iaddr );
$proto = getprotobyname('tcp');
unless ( socket( SOCK, PF_INET, SOCK_STREAM, $proto ) ) {
die "ERROR : init socket: $!";
}
unless ( connect( SOCK, $paddr ) ) { die "no connect: $!\n"; }
my $length = 0;
open (UH,"+< $upfile") or warn "$!\n";
$length += -s UH;
my @head = (
"POST /~zentara/cgi-bin/up1.cgi HTTP/1.1",
"Host: zentara.zentara.net",
"User-Agent: z-uploader",
"Content-Length: $length",
"Content-Type: multipart/form-data; boundary=zzzzzzzzzzzzzzzzzzz",
"",
"--zzzzzzzzzzzzzzzzzzz",
"Content-Disposition: form-data; name=\"file\"; filename=\"$upfile\"",
"Content-Type: application/octet-stream",
"",
"",
);
#try to get total length
my $header = join( "\r\n", @head );
$length += length($header);
$head[3] = "Content-Length: $length";
$header = join( "\r\n", @head );
#recompute
$length = -s UH
$length += length($header);
select SOCK;
$| = 1;
binmode SOCK;
print SOCK $header;
while( sysread(UH, my $buf, 8196 ) ){
if( length($buf) < 8196 ){
$buf = $buf."\r\n--zzzzzzzzzzzzzzzzzzz--\r\n";
syswrite SOCK, $buf, length($buf);
}else{ syswrite SOCK, $buf, 8196 }
print STDOUT '.',
}
close UH;
select STDOUT;
# here is where I think the EOT should be sent
# so I could read the results page, but it hangs
# the socket
#my $data = ();
#print "result->$data\n";
close SOCK;
## ##
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
#my $maxsize = 1024 * 100; #max 100K
my $maxsize = 1024 * 20000; #max 20M
#$CGI::POST_MAX= $maxsize; # max 100K posts !not working right?
#$CGI::DISABLE_UPLOADS = 1; # no uploads
my $query = new CGI;
my $upload_dir = "uploads"; #permissions for dir are set
print $query->header();
if($ENV{CONTENT_LENGTH} > $maxsize){
print "file too large - must be less than $maxsize bytes";
exit;
}
my $file = $query->param("file");
my $filename = $file;
$filename =~s/.*[\/\\](.*)/$1/;
open (UPLOADFILE, ">$upload_dir/$filename");
$/= \8192; # sets 8192 byte buffer chunks, perldoc perlvar
while ( <$file> ){
print UPLOADFILE $_;
#select(undef,undef,undef,.05); #for testing
}
close UPLOADFILE;
print <
Thanks!
Thanks for uploading file : $filename!