Jump to content

[SOLVED] Downloading files above document root


calabiyau

Recommended Posts

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;

	}

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.