title image


Smiley Danke, das wars. Resultat inside ;)
Der Code ist PUBLIC DOMAIN!



sub InitDownload() {

#-----------------------------------------------------------------------------

# InitDownload()

# parameter 1: local filename

# parameter 2: suggested filename for the downloading client

# parameter 3: [optional] suggested filename for the downloading client

# default value is 1 MB

#

# Description:

# The function takes the filename (including path) of some local file and

# outputs it to the client in such way, that a download is initiated and

# that the suggested filename is passed on to the client. Furthermore the

# overall content length is set in the header to allow the client to see the

# proper content length (else it is unknown until the download is complete).

#-----------------------------------------------------------------------------

$| = 1;

my $file = shift;

my $dlfname = shift;

my $sizelim = shift;

if ($sizelim < (1024*1024)) {

$sizelim = 1024*1024;

}

# Get file size

my @fileinfo = stat($file);

my $filesize = $fileinfo[7];

# Output HTTP header

print "Content-Type:application/x-download\n";

print "Content-Length:$filesize\n";

print "Content-Disposition:attachment;filename=$dlfname\n\n";

# Open local file

open(FILE, $file);

binmode(FILE);

if ($filesize <= $sizelim) { # size limit until which the output is not split

# Read the whole file if below size limit

@filecontent = ;

print @filecontent;

} else { # split bigger files

$i = 0;

# Read chunk-wise if $filesize is bigger than $sizelim

do {

$currentblock = read(FILE, $fileblock, $sizelim);

$i += $currentblock;

print $fileblock;

} until ($i >= $filesize);

}

# Close local file when done

close(FILE);

}

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: