Hi,
My upload script which uses upload hook works really nice. After the
upload ends it writes some debug stuff to log file and sends some info
to other host.
When client aborts the upload the reminder of the script after hook is
not executed and i get an error in my apache log:
[Sat Mar 26 14:53:09 2011] [error] [client xxx.xxx.xxx.xxx] (70014)End
+ of file found: Error reading request entity data, referer: http://lo
+calhost/upload
[download]
I'm thinking its the fault of apache, because without abort the script
works just fine. Does anyone have any clue about it ? The script:
#!/usr/bin/perl -w
use strict;
use CGI;
use warnings;
use Digest::MD5 qw(md5_hex);
use POSIX qw/ceil/;
use POSIX 'setsid';
use LWP::Simple;
$CGI::DISABLE_UPLOADS = 0;
$CGI::POST_MAX = 1024 * 1024 * 200;
our $php_exec = '/usr/bin/php';
our $www_root = 'www_root';
our $SERVER_NUMBER = '1';
our $pid = 666;
our $data;
our $first_hook = 1;
our $sum_bytes = 0;
our $approx_file_size = 0;
our $original_filename = "";
our $storage_name = "";
our $db_path = "path where the file with number of stored files is";
our $upload_path = "path to storage folder";
our $debug_path = "path to log folder";
our $url = '';
our $content = '';
#zmienna identyfikująca urzytkownika wyciągnięta z
+pola GET
my $query_string = $ENV{QUERY_STRING};
my $sessid = $query_string;
my $upload_session = $query_string;
$sessid =~ m/userid=([0-9]+)/i;
our $userid = $1;
$upload_session =~ m/us=([a-zA-Z0-9]+)/i;
our $upload_sess = $1;
my $line = 0;
#zmiana aktualnej ilości plików przechowywanych na serwerze
open(UPLOAD_DB, "+<", $db_path."upload_db") or die "Cannot open :
+$!";
flock(UPLOAD_DB, 2);
$line = ;
our $filenumber = $line + 1;
seek(UPLOAD_DB, 0, 0); truncate(UPLOAD_DB, 0);
print UPLOAD_DB $filenumber;
close UPLOAD_DB;
our $dir = ceil($filenumber/5);
unless (-d $upload_path.$dir)
{
mkdir $upload_path.$dir, 0777;
#print $!;
}
$upload_path = $upload_path.$dir."/";
our $logfile = $debug_path."hook_debug.txt";
our $q = CGI->new(\&hook, $logfile, 0);
sub hook
{
our ($filename, $buffer, $bytes_read, $logfile) = @_;
+
$sum_bytes = $bytes_read;
if($first_hook)
{
$approx_file_size = $ENV{CONTENT_LENGTH};
#print $approx_file_size.'\n';
$approx_file_size -= 197;
$original_filename = $filename;
$filename =~ s/^\s+|\s+$//g ;
$storage_name = md5_hex($filename."salt666".$filenumbe
+r);
open(UPLOADFILE, ">>", $upload_path.$storage_name );
chmod 0777, $upload_path.$storage_name;
binmode UPLOADFILE;
print UPLOADFILE $buffer;
close UPLOADFILE;
$first_hook = 0;
}else{
open(DEBUG, ">>", $debug_path."abort_debug.txt" );
binmode DEBUG;
print DEBUG "BR: ";
print DEBUG "$bytes_read\n";
close DEBUG;
open(UPLOADFILE, ">>", $upload_path.$storage_name );
binmode UPLOADFILE;
print UPLOADFILE $buffer;
close UPLOADFILE;
if (($buffer eq '') == 1)
{
unlink($upload_path.$storage_name);
open(DEBUG, ">>", $debug_path."abort_debug.txt" );
binmode DEBUG;
print DEBUG "error file upload aborted\n";
close DEBUG;
exit 0;
}
}
}
open(DEBUG, ">>", $debug_path."end_debug.txt" );
binmode DEBUG;
print DEBUG "END\n#\n";
close DEBUG;
print "Content-type: text/html\n\n END";
exit;
Thank for replies,
Best regards.
--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/