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;

	}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.