When you read a file whose size is a multiple of the readsize (8192 here), then the loop is executed when there are no more data to read.
Here, the result of fread() is not checked, and so the instruction If you serve a file download over PHP with fread and print/echo and experience corrupted binary files, chances are the server still uses magic quotes and escapes the null bytes in your file.
Irritating for me because I was using simple_xml_load to load the file contents as XML, and the problem initially appeared to be that function.
Solution - swap over to file_get_contents or use the loop suggested on the documentation above (see Warning).
Your access to the NCBI website at gov has been temporarily blocked due to a possible misuse/abuse situation involving your site.
This is not an indication of a security issue such as a virus or attack.
Some error checking and data cleanup for invalid/multiple ranges based on
Always calculate a $seek_end even though the range specification says it could be empty... Removed some Cache headers that didn't seem to be needed. Only send partial content header if downloading a piece of the file (IE workaround) It might be worth noting that if your site uses a front controller with sessions and you send a large file to a user; you should end the session just before sending the file, otherwise the user will not be able to continue continue browsing the site while the file is downloading.
PHP5 RC2 with identical settings did not exhibit this behaviour (I was using this for testing).
(tested on Linux (Apache) and Windows (IIS5/6) under PHP4.3.x)Note that the folder from which protected files will be pulled, is set as a constant in this function (/protected) ...
Now here's the function: The following function retrieves a line in a file, regardless of its size, so you won't get an error if the file's size is beyond php's allowed memory limit (the string has to be below however), which is something i was needing for accessing a big log file generated by a webhost.
(It was attempting to buffer the entire 600 Megs or whatever size *before* sending data to the client) if you have this problem you may want to check that first and either not start buffering or close that in the usual way :)Hope that prevents somebody spending hours trying to fix an obscure issue.
Regards :) To make the effects of the latest PHP version changes of the fread function even more explicit: the new size limitation of fread -regardless of the filesize one specifies, in the example below 1024 * 1024- means that if one was simply reading the contents of a text file from a dynamic URL like so: I thought it couldn't hurt to clarify this detail in order to save time for anyone else who is in the same situation as I was tonight when my ISP abruptly upgraded to the latest version of PHP...