#!/usr/bin/perl # MimerDesk # Web based groupware and eLearning environment # www.mimerdesk.org # # Copyright (C) 2001 Ionstream Ltd. # www.ionstream.fi # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed with a hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # $Id: popupload.html,v 1.1.1.1 2001/10/01 21:13:48 inf Exp $ ########################################### # # # MimerDesk: Popup upload # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Teemu Arina # # # ########################################### my $file; my ($total,$size,$realsize,$realtotal) = '0'; my $script = "parent.window.close()\n"; my $upload_data = $ENV{'HTTP_X_FORWARDED_FOR'} || $ENV{'REMOTE_ADDR'}; $upload_data =~ tr/0-9//cd; if (-e "${upload_data}-UPLOAD") { open (FILE, "<${upload_data}-UPLOAD") or $script = undef; $total = || '0'; $file = ; close FILE; if (-e $upload_data) {$size = (-s $upload_data) || '0';} else {$size = $total;} } else {$script = undef;} chomp($total,$file); my $procents = sprintf("%.0f", ($size / $total) * 100) if $total != 0; my $procents_left = 100 - $procents; $procents = '0'if !$procents; $procents .= '%'; $procents_left .= '%'; if ($procents eq '100%') {unlink("${upload_data}-UPLOAD");} else {$script = undef;} $realsize = $size || '0'; $realtotal = $total || '0'; $size = human_readable($size); $total = human_readable($total); $| = 1; if ($file) {$file = 'Uploading file '.$file;} else {$file = 'Waiting for upload to start...';} print "Content-Type: text/html\n\n"; print < Uploading a file
$file

Bytes uploaded: $realsize ($size)

   
$procents

Total file size: $realtotal ($total)

EOF exit; sub human_readable { my $size = shift; if ($size >= (1024*1024*1024)) { $size = sprintf("%.1f", $size/(1024*1024*1024)); $size .= 'G'; } elsif ($size >= (1024*1024)) { $size = sprintf("%.1f", $size/(1024*1024)); $size .= 'M'; } elsif ($size >= 1024) { $size = sprintf("%.1f", $size/1024); $size .= 'k'; } $size = "0" if !$size; return $size; }