Readfilebinary (image) has one more header (0x0A). Hello everyone, our project has encountered a problem. When you use readfile to download an image file, the file will start with one more bit (0x0A) than the original one, and use UEdit to delete the hexadecimal file at the beginning of the file readfile binary (image) the file header will contain one more bits (0x0A.
Hello everyone, our project has encountered a problem. When you use readfile to download an image file, the file will start with one more bit (0x0A) than the original one. you can use UEdit to delete the hexadecimal file at the beginning of the file and read it correctly.
The source code is as follows:
PHP code
The downloaded file is compared with the original file as follows:
Code runs on previous servers without any problems, but when our project changes to the running support environment (the operating system/apache/php versions may be different ), I checked all the documents online and there is no solution. Thank you for solving this problem!
If there is an effective solution, we will append it to 200 points.
------ Solution --------------------
PHP code
// Give you a piece of // $ mime, file type // $ filename, needless to say, // $ data is the file data you want to output, try file_get_contents to obtain if (strpos ($ _ SERVER ['http _ USER_AGENT '], "MSIE ")! = FALSE) {header ('content-Type :"'. $ mime. '"'); header ('content-Disposition: attachment; filename = "'. $ filename. '"'); header ('expires: 0'); header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 '); header ("Content-Transfer-Encoding: binary"); header ('pragma: public'); header ("Content-Length :". strlen ($ data);} else {header ('content-Type :"'. $ mime. '"'); header ('content-Disposition: attachment; filename = "'. $ filename. '"'); header (" Content-Transfer-Encoding: binary "); header ('expires: 0'); header ('pragma: no-cache '); header ("Content-Length :". strlen ($ data);} exit ($ data );
------ Solution --------------------
I just tested your code and didn't see any problems you said.
Ob_clean ();
Flush ();
Remove the two sentences.
------ Solution --------------------
Do you have any output characters before your line of code ??
------ Solution --------------------
There is an extra line break, and it is not your production environment code.
------ Solution --------------------
The source code is as follows:
[Code = PHP]
$ File = 'test_img.bmp ';
Obviously, your
The lower level is that you haven't even avoided BOM headers.