Well, maybe I should reword my question.

I want to place links to PDF files on my site like :

<a href="/pdf/v01.pdf">Click here to download</a>

And I want to log the fact that someone downloaded the file.

So I set Apache up so that all PDF files are handled by Embperl :

EMBPERL_OBJECT_BASE base.epl
<FilesMatch "\.(pdf|html)$">
  SetHandler perl-script
  PerlHandler Embperl::Object
  Options ExecCGI
</FilesMatch>

Inside my "base.epl", I distinguish .pdf from .html and proceed
accordingly :

[$ if ($ENV{SCRIPT_NAME} =~ /\.pdf$/) $]
  [-
    $ENV{SCRIPT_NAME} =~ /.*\/(.*\.pdf)$/;
    my $filename = $1;
    Execute('auth.epl'); # This is where the logging takes place
    if (open(PDF,$ENV{DOCUMENT_ROOT}.$ENV{SCRIPT_NAME})) {
      $http_headers_out{'Content-type'}='application/pdf';
      $http_headers_out{'Content-Disposition'}="attachment; filename=$filename";
      local ($/);
      local ($escmode);
      my $pdf=<PDF>;
      print OUT $pdf;
      close(PDF);
    }
    exit 1;
  -]
[$ endif $]

This worked very well until I switched to UTF8 and discovered that Embperl
was actually loading in the PDF file (like an Execute() ). I thought it would
only do it when it would encounter :

Execute('*');

(which I wouldn't have done for PDF of course) but for some reason, it does read
it. And some PDF files contain some characters, invalid in the UTF8 sense, that
prevent the script to work.

So, is there a way to do what I'm trying to do ?

Thanks a lot for reading this far and for your precious help/hint/guidline...

JC

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscr...@perl.apache.org
For additional commands, e-mail: embperl-h...@perl.apache.org

Reply via email to