Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [perl] pasek postępu uploadu plików
yarek12
post
Post #1





Grupa: Zarejestrowani
Postów: 127
Pomógł: 0
Dołączył: 5.08.2010

Ostrzeżenie: (10%)
X----


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:

  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. use warnings;
  6. use CGI;
  7. use CGI::Carp qw(fatalsToBrowser);
  8.  
  9. my $q = new CGI();
  10.  
  11.  
  12. # Handle actions.
  13. if ($q->param('action') eq "upload") {
  14. # They just submitted the form and are sending a file.
  15.  
  16. my $filename = $q->param('file');
  17. my $handle = $q->upload('file');
  18. $filename =~ s/(?:\\|\/)([^\\\/]+)$/$1/g;
  19.  
  20. # File size.
  21.  
  22. my $size = (-s $handle);
  23.  
  24. # This session ID would be randomly generated for real.
  25. my $sessid = 'my-session';
  26.  
  27. # Create the session file.
  28.  
  29. open (CREATE, ">./sessions/$sessid") or die "can't create session: $!";
  30. print CREATE "size=$size&file=$filename";
  31. close (CREATE);
  32.  
  33. # Start receiving the file.
  34.  
  35. open (FILE, ">./files/$filename");
  36. while (<$handle>) {
  37. }
  38. close (FILE);
  39.  
  40. # Delete the session.
  41.  
  42. unlink("./sessions/$sessid");
  43.  
  44. # Done.
  45. print $q->header();
  46. print "Thank you for your file. <a href=\"files/$filename\">Here it is again</a>.";
  47. }
  48.  
  49. elsif ($q->param('action') eq "progress") {
  50. # They're checking up on their progress; get their sess ID.
  51. my $sessid = $q->param('session') || 'my-session';
  52. print $q->header(type => 'text/plain');
  53.  
  54. # Does it exist?
  55.  
  56. if (!-f "./sessions/$sessid") {
  57. print "error:Your session was not found.";
  58. exit(0);
  59. }
  60.  
  61. # Read it.
  62.  
  63. open (READ, "./sessions/$sessid");
  64. my $line = <READ>;
  65. close (READ);
  66.  
  67. # Get their file size and name.
  68.  
  69. my ($size,$name) = $line =~ /^size=(\d+)&file=(.+?)$/;
  70.  
  71. # How much was downloaded?
  72.  
  73. my $downloaded = -s "./files/$name";
  74.  
  75. # Calculate a percentage.
  76. my $percent = 0;
  77. if ($size > 0) {
  78. $percent = ($downloaded / $size) * 100;
  79. $percent =~ s/\.(\d)\d+$/.$1/g;
  80. }
  81.  
  82. # Print some data for the JS.
  83.  
  84. print "okay:size=$size&received=$downloaded&percent=$percent";
  85. exit(0);
  86. }
  87. else {
  88. die "unknown action";
  89. }


Serwer zwraca jednak następujący błąd: couldn't create child process: 720003: upload.cgi


Z 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.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.09.2025 - 18:18