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

  • Home
  • SEARCH
  • 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 691697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:34:20+00:00 2026-05-14T02:34:20+00:00

Firstly: I’m a lowly web designer who knows just enough PHP to be dangerous

  • 0

Firstly: I’m a lowly web designer who knows just enough PHP to be dangerous and just enough about server administration to be, well, nothing. I probably won’t understand you unless you’re very clear!

The setup: I’ve set up a website where the client uploads files to a specific directory, and those files are made available, through php, for download by users. The files are generally executable files over 50MB. The client does not want them zipped, as they feel their users aren’t savvy enough to unzip them. I’m using the php below to force a download dialogue box and hide the directory where the files are located.

It’s Linux server, if that makes a difference.

The problem: There is a certain file that becomes corrupt after the user tries to download it. It is an executable file, but when it’s clicked on, a blank DOS window opens up. The original file, prior to download opens perfectly. There are several other similar files that go through the same exact download procedure, and all of those work just fine.

Things I’ve tried: I’ve tried uploading the file zipped, then unzipping it on the server to make sure it wasn’t becoming corrupt during upload, and no luck.
I’ve also compared the binary code of the original file to the downloaded file that doesn’t work, and they’re exactly the same (so the php isn’t accidentally inserting anything extra into the file).

Could it be an issue with the headers in my downloadFile function? I really am not sure how to troubleshoot this one…

This is the download php, if it’s relevant ($filenamereplace is defined elsewhere):

downloadFile("../DIRECTORY/files/$filenamereplace","$filenamereplace");

function downloadFile($file,$filename){    
    if(file_exists($file)) {
        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, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        @ flush();
        readfile($file);
        exit;
    }
}

ETA Additonal Info:
– Tests for working/non-working files have been done on the same machine
– If it makes any difference, the original file has a custom icon. After download, the file has a generic blank document icon.

Additonal Info: I THINK THIS ONE’S IMPORTANT!
I just tried downloading the file directly (to bypass the download link that triggers the download function above). If I download the file by just going to its url and downloading it that way, the downloaded file WORKS. So I’m thinking it must have something to do with the download function. But what??

3/17 MAJOR CORRECTION —AND RESOLVED—
So I woke up this morning and it dawned on me that maybe I was comparing the files wrong. (I had re-saved them as binary text, and then compared them. I didn’t realize the comparison program would take and compare actual exe files). This morning I tried comparing the actual exe files and there is a difference. There was one line of php code that was being injected into the first line of the file. I adjusted the php, and the problem was fixed. (It was from the if/else statement that defined teh $filenamereplace variable in the code I’d cited). Thanks again for all your help, and sorry for misleading you in insisting that the files’ contents were identical!

  • 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-14T02:34:20+00:00Added an answer on May 14, 2026 at 2:34 am

    “I’ve also compared the binary code of the original file to the downloaded file that doesn’t work, and their exactly the same (so the php isn’t accidentally inserting anything extra into the file).”

    If that’s really true, then the problem must be in how the exe is started after it has been downloaded. It should certainly not be a problem with your PHP code.

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

Sidebar

Related Questions

Firstly - my description ;) I've got a XmlHttpRequests JSON response from the server.
Firstly, this is not a question about repository synchronisation for which there are numerous
Firstly, I want to restrict this question to web development only. So this is
firstly i just clearify the problem. i am testing the page of login of
Firstly let me clarify (if the title wasn't clear enough): I'm discussing System.Windows.Controls.DataGrid from
Firstly, let me set out what I'd like to do. Assume I have three
Firstly, I'm a newbie to C# and SharePoint, (less than a month's experience) so
Firstly, Real World Haskell , which I am reading, says to never use foldl
So firstly here's my query: ( NOTE:I know SELECT * is bad practice I
I wish to order a table: Firstly by Field1=3 Then by Field2 DESC I

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.