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 6563527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:51:44+00:00 2026-05-25T13:51:44+00:00

I am trying to provide .pdf and .doc files to authorized users on a

  • 0

I am trying to provide .pdf and .doc files to authorized users on a website. The user can only see the file selection page when logged in but this doesn’t prevent an unauthorized user from viewing the documents if they have knowledge of the full URL.

How can I prevent unauthorized users from accessing these files?

  • 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-25T13:51:44+00:00Added an answer on May 25, 2026 at 1:51 pm

    the answer is quite simple,
    @Jonnix has posted this as I was typing but I will explain a little more for you

    one put your files outside of your public HTML directory if your unable to do this look at @Andri answer for an alternative

    E.G cpanel setup

    user/public_html
        /public_html/download.php
    
    user/documents/
        /documents/file.doc
        /documents/file.pdf
    

    @dhh has posted a basic download.php php file however as your wanting to force download their things you can do like finding and supplying the correct mime type here is an extension on to his code as to the best way to 1 force download of a file, and 2 allow different file types

    download.php

    //check users is loged in and valid for download if not redirect them out
    // YOU NEED TO ADD CODE HERE FOR THAT CHECK
    // array of support file types for download script and there mimetype
    $mimeTypes = array(
        'doc' => 'application/msword',
        'pdf' => 'application/pdf',
    );
    // set the file here (best of using a $_GET[])
    $file = "../documents/file.doc";
    
    // gets the extension of the file to be loaded for searching array above
    $ext = explode('.', $file);
    $ext = end($ext);
    
    // gets the file name to send to the browser to force download of file
    $fileName = explode("/", $file);
    $fileName = end($fileName);
    
    // opens the file for reading and sends headers to browser
    $fp = fopen($file,"r") ;
    header("Content-Type: ".$mimeTypes[$ext]);
    // this header tells the browser this is a download and not to try and render if it is able to E.G images
    header('Content-Disposition: attachment; filename="'.$fileName.'"');
    
    // reads file and send the raw code to browser     
    while (! feof($fp)) {
        $buff = fread($fp,4096);
        echo $buff;
    }
    // closes file after whe have finished reading it
    fclose($fp);
    

    P.S here is a big list of mime types if you want to add support for other files
    https://www.freeformatter.com/mime-types-list.html

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

Sidebar

Related Questions

I'm trying to provide two classes to my users - one that is read-only
I am trying to download multiple PDF files as one zip file and then
I am trying to provide drop down menus so that users can select their
I'm trying to extract fields from a pipe-delimited file and provide them as arguments
I'm trying to embed a PDF file into a Word document using the OLE
I am trying to draw a pdf page onto a pdf context and then
I am trying to create a PDF file using struts 2.Action class location is
I'm trying to provide a link to my company's website from a Windows Form.
I'm trying to use django, and mongoengine to provide the storage backend only with
I am trying to provide my users with the option to have my application

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.