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

  • SEARCH
  • Home
  • 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 704217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:55:01+00:00 2026-05-14T03:55:01+00:00

Usually I save documents (images, mpegs, excel, word docs, etc…) for my friends or

  • 0

Usually I save documents (images, mpegs, excel, word docs, etc…) for my friends or family on my website’s root, inside a directory called /files/ or something similar. Nothing too uncommon.

But, I have been playing with user session control, and allowing users to upload files to the dedicated /files/ directory. (the file names are saved in a db, with that user’s ID)

But, that means other people could try to guess and locate other people’s files.
I do randomize the file names, upon upload. And I stop the apache from displaying the /files/ directory content.

However, I’d like to start saving the files outside of the website’s root. This way it can’t be accessible via the browser.

I don’t have any code to show, but I didn’t want to even start on this endeavor if it’s not able to be accomplished. I did find this snippet that shows how to display an image, from outside your website root:

Maybe I can use this for any file type, but has anyone heard of a better way to allow users (logged in) to access their files from online, but not letting other users has similar access?

  • 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-05-14T03:55:01+00:00Added an answer on May 14, 2026 at 3:55 am

    The PHP manual gives good insight on how to achieve this with an example on the readfile function’s page:

    <?php
    $file = 'monkey.gif';
    
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
    ?>
    

    This forces any file to be downloadable by setting the content-disposition and content-type headers. That’s pretty much the way this sort of thing is usually done, file_get_contents will allow you to do the same thing too.

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

Sidebar

Related Questions

Usually, parameter values are copied when being passed on. Using a reference may save
I usually have a sas macro code which automatically run macros Save As and
I would like to generate (and then print or save) big XPS documents (>400
how does version control usually work? does it save diff files as a trail
I usually write scripts for Illustrator and save them in the scripts folder. Then
hello frieds this is how i usually post a variable using Jquery.. $.post(include/save_legatee.inc.php, {
Usually when we push viewcontroller, we will create object for view controller, after that
Usually i'm using cherokee. Due to some critical issues with the latest chrome release
Usually when I'm creating indexes on tables, I generally guess what the Fill Factor
Usually Flash and Flex applications are embedded on in HTML using either a combination

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.