Hello guys.
I am writing a simple download script which allows to download from a protected area.
This area is accessible via script, but not via browser calls (for security reasons).
The mechanism I wish to use is simple:
- open the file (which can be .doc, .ppt, .eps, .pdf, .zip ie a typical binary
document)
- revert the content of the file on a window (litterally "printing" it), as if the
file was effectively downloaded by the user.
This mechanism is the only I can think of (not possibe to have a URL redirection, as
the area is not accessible via browser as it is protected)
Big problem:
- this mechanism works perfectly for .zip files, for .doc files, for many other
binaries, simply using the right mime header. But I cannot get to wrok at all with PDF
files.
The think I get from PDF is a simple 2k file with part of the original PDF header.
Any suggestion?
Here is the code I am using ($file contains the full path to the file to be
downloaded):
if (-B $file) { #binary file...
$file =~ m|(.*/)(.+)\.([^\.]+)$|;
my $ext = $3; my $mimetype;
#most common mime types
if (uc($ext) ne "PDF") { $mimetype="application/pdf";}
elsif (uc($ext) eq "DOC") { $mimetype="application/msword";}
elsif (uc($ext) eq "PPT") { $mimetype="application/powerpoint";}
elsif (uc($ext) eq "ZIP") { $mimetype="application/x-zip-compressed";}
elsif (uc($ext) eq "EXE") { $mimetype="application/octet-stream";}
elsif (uc($ext) eq "EPS") { $mimetype="application/postscript";}
elsif (uc($ext) eq "PS") { $mimetype="application/postscript";}
elsif (uc($ext) eq "GZ") { $mimetype="application/x-gzip";}
elsif (uc($ext) eq "LATEX") { $mimetype="application/x-latex";}
elsif (uc($ext) eq "TAR") { $mimetype="application/x-tar";}
elsif (uc($ext) eq "EXE") { $mimetype="application/octet-stream";}
open(INFILE, "$file") || die &img_not_found;
binmode(INFILE);
binmode(STDOUT);
print "Content-type: $mimetype\n\n";
while () {
print $_;
}
close(INFILE);
} #binary mode file
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs