PC Nerd Posted December 29, 2008 Share Posted December 29, 2008 Hi, I'm trying to get this script to work, so that it still outputs the HTML of the page, and then sends the download. The overall effect is that once the page (HTML) is dowloaded, the File is sent so that the information on the html page is viewable ( it contains information regarding licences and passwords within the file being downloaded). * this code does force the download - just doesnt output any of the HTML. It is called as the last like after all the HTML. I am using output buffering so my code goes: ob_start();HTML outputdownload();ob_flush(); thanks function download() { if(is_file(FILE)) { // required for IE if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression','Off'); } $mime="application/vnd.ms-excel"; header('Pragma: public'); // required header('Expires: 0'); // no cache header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private',false); header('Content-Type: '.$mime); header('Content-Disposition: attachment; filename="'.basename(STATIC_NAME).'"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.filesize(FILE)); // provide file size readfile(FILE); // push it out } *** Un fortunately for some reason the CODE tags didnt work. Quote Link to comment https://forums.phpfreaks.com/topic/138794-solved-force-download-with-html-content/ Share on other sites More sharing options...
RussellReal Posted December 29, 2008 Share Posted December 29, 2008 the best way to do this.. is send the user to a landing page(page with passwords etc).. then open a new window @ the download url with javascript or maybe an iframe could work aswell.. THAN the download box will promt.. and that page won't close.. because when you output the headers to force download.. then add html to the bottom of it.. you're only corrupting the file you want to send.. so do it the way I mentioned Quote Link to comment https://forums.phpfreaks.com/topic/138794-solved-force-download-with-html-content/#findComment-725738 Share on other sites More sharing options...
PC Nerd Posted December 29, 2008 Author Share Posted December 29, 2008 Ahhh ok * Ive tried to format the code above but for some reason its not liking it - so that "dump" of code is the best I can do atm. Thanks - Ill look at the iframe. Quote Link to comment https://forums.phpfreaks.com/topic/138794-solved-force-download-with-html-content/#findComment-725740 Share on other sites More sharing options...
PC Nerd Posted December 30, 2008 Author Share Posted December 30, 2008 Ok - ended up with the target="_blank" option.... and used a cookie across the current page to that ( using the link). That way the file was still only downloadable only once even if they refreshed with the same data etc. Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/138794-solved-force-download-with-html-content/#findComment-725839 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.