billckr Posted May 31, 2007 Share Posted May 31, 2007 Hi all, I've created a document system that allows our company to upload files and create documents for internal use. I've completed the system except for the download system. When a user uploads a physical file say a .xls it's uploads outside of the home dir so it's not accessible via the web to anyone. I'm trying to figure out the standard method for creating a download link for such a file. what it's the most common method for this? How can I cause the header or browser to call and then dowload the said file? Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/53730-force-header-to-download-file/ Share on other sites More sharing options...
Wildbug Posted May 31, 2007 Share Posted May 31, 2007 See the last example on the header() page. <?php // We'll be outputting a PDF header('Content-type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="downloaded.pdf"'); // The PDF source is in original.pdf readfile('original.pdf'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53730-force-header-to-download-file/#findComment-265590 Share on other sites More sharing options...
Daniel0 Posted May 31, 2007 Share Posted May 31, 2007 From the FAQ/Code Snippet Repository: http://www.phpfreaks.com/forums/index.php/topic,95433.0.html Quote Link to comment https://forums.phpfreaks.com/topic/53730-force-header-to-download-file/#findComment-265596 Share on other sites More sharing options...
billckr Posted May 31, 2007 Author Share Posted May 31, 2007 Thank you very much for both answers. While neither one would work 100% for me, I used to 2 examples and this is what is working for me now. // force to download a file $file = pathto/content/$download/$thefile"; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); @readfile($file); Thank you again! Quote Link to comment https://forums.phpfreaks.com/topic/53730-force-header-to-download-file/#findComment-265734 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.