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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:13:15+00:00 2026-05-15T21:13:15+00:00

header(Pragma: public); header(Expires: 0); header(Cache-Control: must-revalidate, post-check=0, pre-check=0); header(Cache-Control: private,false); header(Content-type: application/force-download); header(Content-Disposition: attachment;

  • 0
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"". $file ."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
file_get_contents($file);
readfile($file);
exit();

Any idea what I’m doing wrong? Shouldn’t this download any file from my server to the harddrive of the user? Somehow every file is damaged! Moreover I wonder how I can change the filename of the downloaded file?

$file always contains the full path to my file.
if I try header('Location:' . $file ); the browser successfully opens my file. however if the file is a .jpg the browser doesn’t prompt the download window. instead it just opens the file in the browserwindow. I want every file to be downloaded to the hd.

Please help me guys. I’m after this for over a week now and I can’t find a solution?

  • 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-15T21:13:16+00:00Added an answer on May 15, 2026 at 9:13 pm

    Why not use

    header("Content-type: application/octet-stream");

    Instead of “force-download”

    Also why are you doing file_get_contents and readfile? Only one is needed – You are basically including the file twice which is why it’s corrupted. Here is how I would execute the above code:

    header("Cache-Control: no-cache");
    header("Expires: -1");
    header("Content-Type: application/octet-stream;");
    header("Content-Disposition: attachment; filename=\"" . basename($file) . "\";");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . filesize($file));
    echo file_get_contents($file);
    

    That should be sufficient – so long as the file actually exists

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

Sidebar

Related Questions

The current PHP code being used is : header(Pragma: public); header(Expires: 0); header(Cache-Control: must-revalidate,
The header Cache-Control: max-age=0 implies that the content is considered stale (and must be
A PHP application is offering binary data as a download: header(Content-Type: application/octet-stream); header(Pragma: public);
header(Content-type: image/gif); readfile($filename); The above can only be used to show gif images. Is
header file: private: vector<int*>* nums; public slots: void buttonClicked(); cpp file: NewWindow(){ int one
I have the following code header(Content-Description: File Transfer); header('Content-Type: audio/mp3'); header(Content-Disposition: attachment; filename= .
Header, footer and sidebars have fixed position. In the center a content area with
Header div on top of the 3 columns Height of all columns must fill
header('Access-Control-Allow-Origin: *'); $tmpFile = 'tmpFile.txt'; $val=http://rss.news.yahoo.com/rss/topstories; $curlHandle = curl_init($val); $filePointer = fopen($tmpFile, w); curl_setopt($curlHandle,
I'm using the following script to initiate file downloads: if (file_exists($newfilename)) { header('Content-Description: File

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.