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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:28:50+00:00 2026-06-10T07:28:50+00:00

I have a problem with forcing php to download a file, when i run

  • 0

I have a problem with forcing php to download a file, when i run this code :

  $file = "storage/".$filename;
  header('Content-Description: File Transfer');
  header('Content-Type: '.$mimetype);
  header('Content-Disposition: attachment; filename='.basename($originalfilename));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate');
  header('Pragma: public');
  header('Content-Length: ' . filesize($file));
  ob_clean();
  flush();
  readfile($file);
  exit();

Instead of forcing the browser to download the file, it show all content of file.
For example when i want to force the browser to download test.png, browser shows alot of unknown symbols (exp. �q�M�6�%V�һK.. ) in itself. How can i force the browser to download the file instead of showing it?

I used Live HTTP Headers and when i click the download button in this page:
http://www.helios.ir/get.php?file=17/dl.php?name=56379948c6df5e49d3073aee14358e3fc98ba5ae.jpg

It shows this headers:

----------------------------------------------------------
http://www.helios.ir/download.php?file=17.jpg&name=56379948c6df5e49d3073aee14358e3fc98ba5ae.jpg

GET /download.php?file=17.jpg&name=56379948c6df5e49d3073aee14358e3fc98ba5ae.jpg HTTP/1.1
Host: www.helios.ir
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Referer: http://www.helios.ir/get.php?file=17/dl.php?name=56379948c6df5e49d3073aee14358e3fc98ba5ae.jpg
Cookie: mfh_mylang=en; mfh_sess_id=effccfb2429a54b6f26ef2f155144c98; mfh_logined=0; mfh_uid=0; mfh_last_click=1345470635; __utma=44342077.1613075140.1345761327.1345912829.1345927090.14; __utmz=44342077.1345910409.12.11.utmcsr=localhost|utmccn=(referral)|utmcmd=referral|utmcct=/share6/get.php; __utmb=44342077.18.10.1345927090; PHPSESSID=bb18789f8011836092f4e2d14aa3118d; __utmc=44342077

HTTP/1.1 200 OK
Date: Sat, 25 Aug 2012 22:25:01 GMT
Server: Apache/2.2.22 (CentOS)
X-Powered-By: PHP/5.2.17
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
----------------------------------------------------------
  • 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-10T07:28:52+00:00Added an answer on June 10, 2026 at 7:28 am

    In the response headers you just posted no Content-Disposition: attachment appears… You should probably drop the ob_clean() call (or, at the very least, move it before the header() calls*).

    Also, that flush() is completely pointless (what’s the point of flushing an empty buffer?). Remove it.


    *provided you called ob_start() beforehand – typically at the start of your script

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

Sidebar

Related Questions

I have this sample code ( below ), example1() method works with no problem,
I have a problem with forcing download of some mp3/zip files. The problem is
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with TableView its empty. In (.h) file: @interface TableViewController : UITableViewController{
Folks, I know there have been lots of threads about forcing the download dialog
I have an upload PHP script and before it uploads the file, it renames
I have a problem with Javascript forcing the [object DOMWindow] into an function I
I have a problem importing a CSV file with RapidMiner. Floating point values are
This is my first shot at brute-forcing the NP-complete knapsack problem . In this
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar

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.