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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:20:52+00:00 2026-05-29T18:20:52+00:00

It is common to server downloadable files which are located outside the public folder

  • 0

It is common to server downloadable files which are located outside the public folder by PHP:

$fp = fopen($file,"r") ;
header("Content-Type: application/msword");
header('Content-Disposition: attachment; filename="'.$filename.'"');

while (! feof($fp)) {
    $buff = fread($fp,4096);
    echo $buff;
}

I have two questions:

  1. Comparing with static files served by web server (direct file URL); does this method needs more resources (memory and cpu), as PHP needs to read the file and deliver?

  2. How we can display some text on the page? As we defined header, we do not have html output of the php script.

  • 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-29T18:20:55+00:00Added an answer on May 29, 2026 at 6:20 pm

    1 Since you have to process the file with this script it require more
    resources than just normal download link. However this is depend on your needs. If you think these files need more security. Let’s say only authenticated users can download the file and only the file belongs to him. Then you need to validate those. In such situation you need the code you have put in your question. If your files are open to the public then you can display direct link to the file may be locating them somewhere in public temporarily.

    2 I can suggest you two methods to perform this.

    Method 1 :

    You need javascript support to perform this kind of requirement in handy way. Assume you need to display some HTML on the page where the download is possible. You can create a page with the HTML you want and you can put a download button.

    <input type="button" name="cmdDownload" id="cmdDownload" value="Download" onclick="downloadFile('<?php echo $pathToTheFile; ?>');" />

    And you can keep hidden iframe to process the download.

    <iframe id="downloadFrame" style="display:none"></iframe>
    

    Assume your PHP download page is download.php.

    Then you can have a javascript function like this.

    <script type="text/javascript">
    function downloadFile(filepath) 
    {
        var ifrme = document.getElementById("downloadFrame");
        ifrme.src = "download.php?filepath="+filepath;
    }
    </script>
    

    Method 2:

    Other than above method you can use META Refresh as well.

    <meta http-equiv="Refresh" content="3;URL=<?php echo $fullHTTPathToYourFile ?>" />
    

    You can have HTML display with this too.

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

Sidebar

Related Questions

Which options are there to make your 3-Tier System. Client / Common / Server
I am thinking to save server load, i could load common javascript files (jquery
We have a common SharePoint server which runs an internal SharePoint site. Our teams
Common situation: I have a client on my server who may update some of
I have a Client/Server application, where the Client and Server have some common tables
Sys.Webforms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for
I am moving a system from a VB/Access app to SQL server. One common
I've a class which is a wrapper class(serves as a common interface) around another
Looking back at an internal system I just built, the common server / page
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for

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.