Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:43:02+00:00 2026-06-02T13:43:02+00:00

I have files stored outside the public_html folder for security purposes. However, I would

  • 0

I have files stored outside the public_html folder for security purposes. However, I would like to link to specific files somehow where a user could download one of these files.

I am using a jquery script that allows me to specify a server PATH as an upload folder, and it does upload outside the public_html folder.

The only problem is it requires me to specify a URL to the “upload path” which is used to download the files. I thought I might be able to something like:

public_html/redirect (contains htaccess which forwards all requests to "hiding" folder)

hiding (outside public_html)

A user clicks /redirect/file.doc and they download a file located at hiding/file.doc

Is this possible? If not, how can I give specific file download access to files outside of my public_html directory? I know I’ve seen it done on other scripts before…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:43:09+00:00Added an answer on June 2, 2026 at 1:43 pm

    You can do this with "php download handler":

    You can use method like this one to return file contents and file information headers to users browser, just make sure that nothing else is outputted before this.

    I suggest that you put this to separate file and call that for example download.php.

    function returnFile( $filename ) {
        // Check if file exists, if it is not here return false:
        if ( !file_exists( $filename )) return false;
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        // Suggest better filename for browser to use when saving file:
        header('Content-Disposition: attachment; filename='.basename($filename));
        header('Content-Transfer-Encoding: binary');
        // Caching headers:
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        // This should be set:
        header('Content-Length: ' . filesize($filename));
        // Clean output buffer without sending it, alternatively you can do ob_end_clean(); to also turn off buffering.
        ob_clean();
        // And flush buffers, don't know actually why but php manual seems recommending it:
        flush();
        // Read file and output it's contents:
        readfile( $filename );
        // You need to exit after that or at least make sure that anything other is not echoed out:
        exit;
    }
    

    Extending it for basic use:

    // Added to download.php
    if (isset($_GET['file'])) {
        $filename = '/home/username/public_files/'.$_GET['file'];
        returnFile( $filename );
    }
    

    Warning:

    This is basic example and does not take into account that user may try to take some evil advantages of $_GET that is not properly sanitized.

    This means basically that user can for example retrieve passwd file or some other sensitive information if certain conditions apply.

    For example, retrieving /etc/passwd:

    Just point browser to http://server.com/download.php?file=../../../etc/passwd and server returns that file. So before real use you should find out how to properly check and sanitize any user supplied arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a subdomain xxx.yyy.com running Apache. The files are stored in /home/someone/public_html/xxx
In the past I have stored database credentials (username, password) in another file (outside
I have some files stored at amazon. all in private mode, and since I
I have some files stored in a database blob column in Oracle 9. I
I have various custom binary files stored in perforce and for many of the
I have currently got imagepaths stored within the database and image files stored in
I have an app that generates invoices in the form of PDF files stored
I have a series of Rackspace Cloud Files CDN URLs stored which reference an
I have other pages within my app preferences which are stored as separate files
I have a set of records, stored as XML files, where the XML files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.