calabiyau Posted May 3, 2007 Share Posted May 3, 2007 I have client files stored above the document root level for security without having to get into htaccess files, but want it set up so that each client can access their files. All the file information is stored in the database and I have managed to get it working, just testing it out with a microsoft word document. The problem is the downloaded document contains the html source of the page above the document contents. Anybody know what i'm doing wrong here? Some kind of header problem? if ($_GET['action']=='download') { $location = "../ext_client_doc/".$_GET['user']."/".$_GET['doc']; $fd = fopen($location, 'rb'); header("Cache-Control: "); header("Pragma: "); header("Content-Type: application/octet-stream"); header("Content-Length: " .(string)(filesize($location)) ); header('Content-Disposition: attachment; filename="'.$_GET['doc'].'"'); header("Content-Transfer-Encoding: binary\n"); ob_flush(); flush(); while(!feof($fd)) { $buffer = fread($fd, 2048); print $buffer; } fclose ($fd); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/49745-solved-downloading-files-above-document-root/ Share on other sites More sharing options...
Ravo Posted May 3, 2007 Share Posted May 3, 2007 Are you printing or echo'ing anything before you run that section of code? Quote Link to comment https://forums.phpfreaks.com/topic/49745-solved-downloading-files-above-document-root/#findComment-243959 Share on other sites More sharing options...
calabiyau Posted May 3, 2007 Author Share Posted May 3, 2007 Yes, actually i've just looked and all the html source that has been printed in the document is that which came before the code. But this is an add on module within the content section of the page, so I can't just pick up it up and put it at the top. Is there no way to prevent that from happening without making it come first in the code? Quote Link to comment https://forums.phpfreaks.com/topic/49745-solved-downloading-files-above-document-root/#findComment-243969 Share on other sites More sharing options...
calabiyau Posted May 3, 2007 Author Share Posted May 3, 2007 Solved via ob_get_clean which cleared the current contents of the buffer before the file was added. Quote Link to comment https://forums.phpfreaks.com/topic/49745-solved-downloading-files-above-document-root/#findComment-243985 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.