My upload function looks like:

sub Upload_File{
    my ($file, $mime) = @_;
    my $file_data   = param('filename');

    my $buffer = undef;

    UnTaint($file);

        if ($mime =~ /text/) {
                sysopen(VAULT, "$path/$file", O_RDWR | O_EXCL |
O_CREAT | O_TEXT) or die "couldn't create $file for R/W: $!\n"; }
        else {

                sysopen(VAULT, "$path/$file", O_RDWR | O_EXCL |
O_CREAT | O_BINARY) or die "couldn't create $file for R/W: $!\n";
                binmode(VAULT, ":utf8");
        }

        my $upfh = \*VAULT;
        flock $upfh, 2;
        sysseek $upfh, 0, 0;
        select((select($upfh), $| = 1)[0]);
        while( sysread($file_data, $buffer, 1024) ) {
                syswrite($upfh, $buffer) or die "couldn't write $upfh:
$!\n";
        }

        close $upfh;
}

When I am using read and print with FastCGI upload script, files
uploaded with corruptions (including simple text files), this is
because perl uses buffered I/O. This why i've tried to use non-
buffered I/O, syswrite and sysread, as a result files are corrupted
anyway. Fot a web-server i'm using nginx:

                fastcgi_pass   localhost:9000;
                fastcgi_index  index.pl;
                fastcgi_read_timeout    5m;
                fastcgi_buffers  8  4k;
                fastcgi_max_temp_file_size 0;

Maybe some body can help me?


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to