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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:52:59+00:00 2026-05-23T01:52:59+00:00

I have a force-download script that produces good results with PDF and plain text,

  • 0

I have a force-download script that produces good results with PDF and plain text, and is semi-OK with ZIP archives (they work in Windows, not in Linux). However, application files and images all fail. These make up the vast majority of the files I must handle. Zipping all downloads, as I’ve seen suggested on similar topics here, is not an option.

The failing files download to their full size, and are written to disk under the correct name. Attempts to open them result in a error message, which differs between types. Comparing downloaded files to their originals in hexdump, I can see that the script inserts the following characters at the start of each downloaded file:

ef bb bf

The downloaded file then reproduces the original until it stops at its specified size – so the original’s last 6 characters are always missing.

Unfortunately I know nothing about how binary files are made up, what these characters might mean, or how/why the script is inserting them.

This is the script as-is:

$file = '94.ppt';
$path = $_SERVER['DOCUMENT_ROOT']."/relative/path/";
$full_path = $path.$file;
if ($fd = fopen ($full_path, "r")) {
    $fsize = filesize($full_path);
    $path_parts = pathinfo($full_path);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "pdf":
            header("Content-type: application/pdf");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
        break;
        case "txt":
            header("Content-type: text/plain");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
        break;
        case "jpg":
            header("Content-type: image/jpeg");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
        break;
        case "ppt":
            header("Content-Type: application/vnd.ms-powerpoint");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
        break;
        default;
            header("Content-type: application/octet-stream");
            header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    header("Content-Transfer-Encoding: binary");
    header("Content-length: $fsize");
    header("Cache-control: private");
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);
exit;

The development system is PHP 5.3.2-1 on Apache 2.2.14 (Ubuntu). The production host is PHP 5.2.9 on Apache 2.0.63 (some type of Linux).

  • 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-23T01:52:59+00:00Added an answer on May 23, 2026 at 1:52 am

    EF BB BF is the UTF-8 encoding Byte Order Mark (BOM). I suspect there is some configuration option to turn off the BOM.

    Edit: File editors should allow you to turn off the BOM when saving an file in relevant character encodings (e.g. UTF-8).

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

Sidebar

Related Questions

I have a script that allows users to 'save as' a pdf, this is
I have a script that download's files from a server, all works nice. But
I have a very simple and standard PHP force download script. How do I
I have a code which force download a pdf file. Code below $file_name =
I have a php script that I have used for years to force downloads
I have a script that forces a download and I make a call to
I want to force the download of an image. I have found this code:
I have a d3 force-directed graph that contains a group of nodes: var node
I have a very painful slow script that gets lots of data from MySQL
I have a PHP script being served over https:// that is trying to push

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.