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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:44:57+00:00 2026-06-01T04:44:57+00:00

All i need help in downloading a file through headers its working fine but

  • 0

All i need help in downloading a file through headers its working fine but the problem is that the file is place in a folder and i don’t understand how to give path for that specific file. the file downloads always give me empty file. My basic sanario is that i click a link(image) for download a file on page named(documents.php) which send me to the other page named download.php.in that page i set header for downloading the clicked file like

this is a link (document.php)

<a href="download.php?title=<?=$arr['title']?> "><img src="images/xl_icn.jpg" alt="" width="19" height="20" /></a>

this is header(download.php)

header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');

header("Content-Disposition: attachment; filename='".$_GET['title']."'");

if(isset($_SESSION)){
  header('Location: documents.php');
}

and after downloading it send me back to the documents.php page but the files which i want to download is in folder uploads/documents and i dont know how to download that files placed in uploads/documents.

  • 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-01T04:44:58+00:00Added an answer on June 1, 2026 at 4:44 am

    You have a good start I would modify your code to be more like the following:

    $path = $_SERVER['DOCUMENT_ROOT']."/uploads/documents/";
    $fullPath = $path.$_GET['title'];
    
    if ($fd = fopen ($fullPath, "r")) {
      $fsize = filesize($fullPath);
      header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
      header("Content-Disposition: attachment; filename='".$_GET['title']."'");
      header("Content-length: $fsize");
      header("Cache-control: private");
      while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
      }
    }
    fclose ($fd);
    

    $path you would update for what folder
    The if statement works the required file calls and echos the page content in a buffer style.

    This can be further expanded to include a switch statement depending on extensions to change the Content-type declaration. Since you will buffer the content to the page, you cannot call header("Location");. Or you will get “header cannot be sent since page content has loaded” due to the buffering.

    I would suggest opening it in a new window or a iframe (wrapped in a div and could be hidden) on the page. You could also include it in the document.php file as well instead of calling a separate file.

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

Sidebar

Related Questions

I need help to replace all \n (new line) caracters for in a String,
Greetings all, I need help combining some htaccess rewrites, these crazy regular expressions screw
I need some help with SQL Query. I am trying to select all records
All, I need your help to merge the result in the same datetime in
We Really need some help on this one: We've Struggled with all the Apple
I am new to all the anonymous features and need some help. I have
I need a little help creating a catch-all error handling page in my ICEfaces
Hey all i am in need of some help trying to figure out how
Need a little help with my jquery here I want all my button with
I use Fullcalendar on my site, but I need all text in different language.

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.