Witam,
Już od dłuższego czasu próbuję napisać pasek postępu, przepatrzyłem praktycznie cały internet i wszystkie możliwości, jednak nie znalazłem żadnego działającego rozwiązania.
Więc postanowiłem spróbować z perlem, oto mój kod uploadu:
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI();
# Handle actions.
if ($q->param('action') eq "upload") {
# They just submitted the form and are sending a file.
my $filename = $q->param('file');
my $handle = $q->upload('file');
$filename =~ s/(?:\\|\/)([^\\\/]+)$/$1/g;
# File size.
my $size = (-s $handle);
# This session ID would be randomly generated for real.
my $sessid = 'my-session';
# Create the session file.
open
(CREATE
, ">./sessions/$sessid") or
die "can't create session: $!";print CREATE
"size=$size&file=$filename"; close (CREATE);
# Start receiving the file.
open
(FILE, ">./files/$filename");while (<$handle>) {
}
# Delete the session.
# Done.
print "Thank you for your file. <a href=\"files/$filename\">Here it is again</a>."; }
elsif ($q->param('action') eq "progress") {
# They're checking up on their progress; get their sess ID.
my $sessid = $q->param('session') || 'my-session';
print $q->header(type
=> 'text/plain');
# Does it exist?
if (!-f "./sessions/$sessid") {
print "error:Your session was not found."; }
# Read it.
open (READ, "./sessions/$sessid");
my $line = <READ>;
close (READ);
# Get their file size and name.
my ($size,$name) = $line =~ /^size=(\d+)&file=(.+?)$/;
# How much was downloaded?
my $downloaded = -s "./files/$name";
# Calculate a percentage.
my $percent = 0;
if ($size > 0) {
$percent = ($downloaded / $size) * 100;
$percent =~ s/\.(\d)\d+$/.$1/g;
}
# Print some data for the JS.
print "okay:size=$size&received=$downloaded&percent=$percent"; }
else {
}
Serwer zwraca jednak następujący błąd:
couldn't create child process: 720003: upload.cgiZ góry dziękuję za pomoc, bardzo mi na tym zależy, ewentualnie jeśli ktoś zna inny sposób na pasek postępu, również będę wdzięczny.
Pozdrawiam.