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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:40:28+00:00 2026-06-11T08:40:28+00:00

I work as a lab instructor and was trying to ensure that my students

  • 0

I work as a lab instructor and was trying to ensure that my students can’t download their starter files early by keeping the files above the webroot and forcing them to log in (authenticated through the university’s LDAP), verifies that it is past the release time then sends them the file using readfile. Unfortunately any files I send end up corrupted.

My code is:

if (file_exists($path)) {
     //header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename='.basename($path));
     //header('Content-Transfer-Encoding: binary');
     header('Expires:' . date('r', 0));
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     //header('Pragma: public');
     header('Content-Length: ' . filesize($path));
     //ob_clean();
     //flush();
     readfile($path);
     exit(0);
 }

I even tried sending just plain text which also didn’t transfer correctly, just ended up with gibberish.


Edit:

Sorry I was remiss in specifying what I have already tried. I did try sending a simple text file (trying to examine a pdf in notepad looking for PHP warnings is a bit much).

I sent a file with only the contents This is plain text and the result was pure gibberish. Mostly non-printable characters. 1f 8b 08 00 00 00 00 00 00 03 0b c9 c8 2c 56 00 a2 82 9c 00


Update:

Disabled the gzipping on one of the servers and the files were still corrupted. removed the ob_clean(); flush() and the text files started coming through cleanly (can’t believe enerything you read on the internet :/ ).

Zip files were still corrupted but my PDFs were now readable. Did some more looking and it appears that there is an extra newline being added at the very start of the file. Looking back at the text file it does have an extra newline at the front and the last character is missing. As expected adding +1 to the Content-Length header lets the last character come through, still looking for where the prepended newline is coming from. Also, if I comment out the readfile I get a file with only CRLF (0d0a) in it.

The framework normally ‘wraps’ the content from the controller with a view and then a layout but both are set to blank files and the head controller is checking that they are blank and then skipping the line to echo the generated HTML. Even then the exit(0) should ensure that only destructors get called after the transfer. I verified this by putting echo statements in the layout and view and increasing the content size accordingly and that text isn’t ending up in the downloaded file so I’m relatively certain that the newline isn’t coming from there.

  • 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-11T08:40:29+00:00Added an answer on June 11, 2026 at 8:40 am

    Ensure the PHP script does not contain empty lines out of <?php ?> tags. In general, ensure no other stuff is echoed, but the file.

    It would be very helpful if you post resulting file contents here, please. Try with a simple one-line text file.

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

Sidebar

Related Questions

string antcbatchpath = @C:\Work\6.70_Extensions\release\SASE Lab Tools\ANT Builds\antc.bat in the above string, if i would
I am a student trying to finish a lab assignment. I have two files,
I have a ton of data that needs to be processed from lab work.
I often use Octave to create data that I can plot from my lab
I'm trying to work out an automated Build-Deploy-Test workflow using Lab Management/VS 2010 and
I work with unordered_set . Here it's written that it has a reserve function
I work for a medical lab company. They need to be able to search
my robotics lab is looking for programmers to work on some projects we have
I'm trying to capture key events in a mx:Image and I can't get it
I am using Paypal lab Integration wizard to put express checkout work on my

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.