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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:35:22+00:00 2026-06-01T05:35:22+00:00

I have a file download code in my site which worked perfectly fine untill

  • 0

I have a file download code in my site which worked perfectly fine untill i changed domain.
I have checked all the links and changed everything and they work FINE
Yet for some reason the file is downloaded corrupted and i can’t figure out why.

Code:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$fileName.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_url));
readfile($file_url);
exit;

$FileName has name + extension. $file_url is Working Fine. if i echo the url and try to browse to it i see the file.

Any help someone?

EDIT:
I have noticed that the browser says : Resource interpreted as Document but transferred with MIME type image/png

  • 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-01T05:35:24+00:00Added an answer on June 1, 2026 at 5:35 am

    If the files being downloaded are images (as mentioned in the comments), then the Content-Type header should be the appropriate mime-type for that image eg. "image/jpeg", "image/png", etc.

    $size = getimagesize($file_url);
    header("Content-type: {$size['mime']}");
    

    "application/octet-stream" should not be used in this instance (often used in the past to attempt to force a download, since the browser won’t necessarily know what to do with it). The "Content-Disposition: attachment" header is what triggers the download.

    Also, you mention the original filename is in Hebrew… The "filename=" header should specify a filename in US-ASCII for compatibility. UTF-8 is possible but only with some additional ‘messing around’, and still might not be compatible with some browsers.

    EDIT#1

    If you are using output buffering then you might need to ensure the output buffer is empty and flushed before attempting to download the file, otherwise whatever is in the output buffer will become part of your downloaded file and it will be corrupted.

    header('Content-Length: ' . filesize($file_url));
    ob_clean();    // <<<<
    flush();       // <<<<
    readfile($file_url);
    

    EDIT#2 – Content-Type

    Following your link to the answer of that other question that suggests using application/octet-stream instead of image/jpg… the answer in that question quotes RFC 2616, however, this has been superseded by RFC 6266 where it states:

    According to RFC 2616, the disposition type "attachment" only applies
    to content of type "application/octet-stream". This restriction has
    been removed, because recipients in practice do not check the content
    type, and it also discourages properly declaring the media type.

    So, it is more correct to specify the correct mime-type for the image (as mentioned above). Although, at the end of the day, what is important is what works for you as servers/browsers do vary and don’t necessarily follow the standards unfortunately.

    To further back up the argument for specifying the correct mime-type, and not using "application/octet-stream", see the following accepted answer to a question on webmasters…

    What could keep Chrome from downloading files?

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

Sidebar

Related Questions

I am trying to download a source code file from a web site which
I have this code to download a file, but on sourceforge.net sever there is
i have done a code that will download the file from internet. but the
I have trouble shooting at file download problem. In Chrome, the download works fine.
I have a app which will download a file from web. The download action
I have a file download script that I have written, which reads files from
i have a site where people can download source code, sorta paste type site,
I am creating Excel file download using NOPI libraries. I have lot of data
I have a need to rename a file after download using php cURL. Here's
I have a functionality where a user is given file to download. It works

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.