php - Google Chrome Cache PDF files -


i have built small php/mysql internal app host , sort documents. works until comes updating file, in case .pdf file. when user updates .pdf new file on server expected , older version deleted. user getting new version providing never opened old version.

now problem.... if user has opened older version of .pdf @ point in past not newer version when link clicked view document though new version physically on server.

i'm guessing google chrome browser caching older version of pdf somewhere. how can around this? due amount of users , number of times day of documents updated asking users manually clear cache not practical.

you have 3 choices here:

  1. change filename everytime gets updated
  2. always generate href parameter
  3. send header information telling browser download fresh server

option 1 - works in 100% of cases. might tricky maintain

echo '<a href="files/pdfs/'.$row['filename_from_database'].'">pdf</a>';  // produce like: // <a href="files/pdfs/filename_v5.pdf">pdf</a> 

option 2 - works in 99% of cases

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

option 3 - works in 99% of cases

header("pragma: public"); header("cache-control: maxage=1"); // <-- important header('expires: '.gmdate('d, d m y h:i:s', time()+1).' gmt'); header('content-type: application/pdf'); exit(file_get_contents(path_to_pdf_file)); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -