0

I would like to know how a full pathname call for a pdf can be served showing only the enclosing folder URL. This is for keeping the URLs minimal while doing some logging.

The file structure for each in a series of documents is (example):

/mysite.com/docs/doc-4-5/
    index.php
    document-4-5.pdf

The index does some logging, then redirects:

doLogging(); 
header('Location:document-4-5.pdf');

This works. A call to the folder returns the pdf. But the return URL includes the pdf's full pathname, and I would like it to show only the enclosing folder name, so when you get the pdf, the URL you see is (example):

/mysite.com/docs/doc-4-5/

Thus, refresh calls for the pdf, or any full pathname call to it, will always go through the index.

It seems this can be done with redirect, but I have not been able to do it, and will appreciate guidance.

Thank you.

Andante88
  • 55
  • 1
  • 1
  • 8
  • Don't use `header` in your `index.php`. Just open pdf file and write output with correct content-type – anubhava Feb 06 '20 at 14:38

1 Answers1

0

Thank you. This is working:

doLogging();
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="document-4-5.pdf"');
readfile('document-4-5.pdf');

Clicking the pdf's name (link) in the main directory does the download without opening the pdf in the browser, as suggested.

Andante88
  • 55
  • 1
  • 1
  • 8