And So I am building a credit card applicatoin that necessitates redirecting (or perhaps is it spinning? I have to perform the one in which the URL continues to be same around the client side) to some .php apply for all demands that occur for .pdf files inside a given directory on my small web server (Apache). However, I only want this request to become rewritten when the user is attempting to show the PDF inside a browser (not download it). I've got a feeling this second part isn't feasible.

Does anybody possess some good assets to consider that does not only illustrate the syntax which i will have to use but additionally what's going on behind the curtain using the Apache server?

Also, does anybody know regarding the way i can determine whether the file has been directly downloaded or asked for via web-browser? I've got a feeling that, for how long you access a Pdf using a browser, it appears to download it and display it while using Adobe Readers wordpress plugin, that there's no distinction that may be made between your two.

Sincerely,

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On

   # only if not an actual file exist
   RewriteCond %{REQUEST_FILENAME} !-f

   # only if not an actual directory exist
   RewriteCond %{REQUEST_FILENAME} !-d

   RewriteRule /your-directory/path/(.+)\.pdf $1.php [NC,L]
</IfModule>

1. It's spinning.

2. There's no distinction between viewing and installing. If your request is received because of your Apache server, it'll provide a response. The response is going to be whatever your PHP script will output. Update: @corretge has given an answer associated with this. I believe it isn't entirely reliable to depend on headers sent through the client, but you can test that solution.

3. Here you can study about Apache's mode_rewrite

Not examined, but you may also try:

RewriteRule ^(.+)\.pdf$  /downloadPdf.php?pdf=$1.pdf [L,NC,QSA]

As well as in the /downloadPdf.php script query for HTTP headers with headers_list() if these can be found:

header("Content-Type: application/force-download");
header("Content-Type: application/download");

If download headers can be found, send the file with

  header("Content-Disposition: attachment; filename=\"" . stripslashes($this->ubqDoc[$this->camp]['name']) . "\"");

And also the pressure download headers.

Else, send the file with this particular header

  header("Content-Disposition: inline; filename=" . stripslashes($this->ubqDoc[$this->camp]['name']));

You have to manage other headers, like Content-Type and Content-Lenght

Browse the fpassthru PHP manual about send files from PHP.