papaScott Posted June 21, 2011 Share Posted June 21, 2011 Hello everyone, I have a small php app that will inject data into a file, then allow the user to download the file. the problem is that the file they download doesn't seem to be the most recent one. I've checked the file on the server, and then i've downloaded the file using the app. It seems to be a cache issue, as the browser is holding the file in temp internet files for fast access. what can i do to resovle this? Do i have any other options besides adding a time stamp in the file name, thus having the browser redownload the file. Please help if you can. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/240003-possible-cache-problem/ Share on other sites More sharing options...
TeNDoLLA Posted June 21, 2011 Share Posted June 21, 2011 Try adding these in the <head></head> section of your app to prevent browser from caching. <META Http-Equiv="Cache-Control" Content="no-cache"> <META Http-Equiv="Pragma" Content="no-cache"> <META Http-Equiv="Expires" Content="0"> Quote Link to comment https://forums.phpfreaks.com/topic/240003-possible-cache-problem/#findComment-1232830 Share on other sites More sharing options...
AbraCadaver Posted June 21, 2011 Share Posted June 21, 2011 Assuming you are using a link to directly download the file you can add something meaningless to the URL that makes it different each time: echo '<a href="http://www.example.com/downloads/file.txt?id=' . time() . '">'; Or if you have a PHP script that gets and then outputs the file contents for download, then you can add some no-cache and expire headers before the output. I don't remember for what browsers certain ones of these are necessary so I included all of them. Something like: header('Expires: Sat, 01 Jan 2011 05:00:00 GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header('Pragma: no-cache'); Quote Link to comment https://forums.phpfreaks.com/topic/240003-possible-cache-problem/#findComment-1232834 Share on other sites More sharing options...
papaScott Posted June 21, 2011 Author Share Posted June 21, 2011 thank you for all the answers I added the pointless info onto the link, and it seems to solve the problem. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/240003-possible-cache-problem/#findComment-1232841 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.