Open updated PDF

0

Well, I have a PHP system that builds a PDF. After that, I have a common html link that opens the pdf on screen normally, until then everything is ok.

But if I modify the contents of the PDF, and give the command to the system to rebuild it with this new information, when clicking the link to open, it opens the old pdf, I can only see the new one if it gives an "F5 ".

Does anyone know an alternative to always open the already updated file and not the cache version?

PS: The link opens the ready file that is saved on the server.

    
asked by anonymous 17.01.2017 / 18:51

2 answers

2

A better approach would be to use header() to tell the browser that the content of the request should not have a cache.

header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1
header('Pragma: no-cache'); // HTTP 1.0
header('Expires: 0'); // Proxies

Source: Preventing cache of inline PDF

    
17.01.2017 / 19:25
1

There are several ways to solve this problem, from html to javascript. However the easiest would be to create a variable link, either by the name of the pdf file or by a parameter:

echo '<a href="files/pdfs/filename.pdf?q='.microtime(true).'">PDF</a>';

The most slick form would actually always change the name of the pdf file. However it is not very practical or legal. A parameter in the URL works almost 99% of the time

Source: stackoverflow in English

    
17.01.2017 / 19:03