Readfilebinary (image) has one more header (0x0A). how can this problem be solved?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.