Re: RE: help with pdf file download?

2002-10-16 Thread cerberos

Thanks Josh for noticing that typo.
unfortunately that's not the problem. 

I simply cut'n'pasted the wrong version of code yesterday (I had many different 
attempts with various methods and I tried at the end to have a separate case for PDF 
which at the end I aborted forgotting to change it back to 'eq').

My original correct code is: 
if (-B $file) { #binary file...
 
   $file =~ m|(.*/)(.+)\.([^\.]+)$|;
   my $ext = $3; my $mimetype;

   #most common mime types
   if (uc($ext) eq "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";}   

  my $size = -s "$file";

 
  open(INFILE, "$file") || die &img_not_found;
binmode(INFILE);
binmode(STDOUT);
print "Content-type: $mimetype\n\n";
while () {
print $_;
}
close(INFILE);
   

  } #binary mode file


The mime type is correctly set (I am sure as I debugged it step by step and printed 
out everything at each step). 
The output (downloaded file) is perfectly working for .doc files and for .zip files 
(the ones I tried).

But for PDFs, the output is all the time a 2kb with the PDF header and binary parts. 
But nothing to do with the original PDF. 

Any suggestions? I tried with an IIS server on WinNT and Sambar server on WinNT. 
Can anyone test the code above or give further suggestions?

Thanks

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



help with pdf file download?

2002-10-15 Thread cerberos

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