ReadFile binary (image) file header will be one more (0x0A). How to Solve

Source: Internet
Author: User
Tags readfile
ReadFile binary (image) file header will be one more (0x0A).
Hello everyone, now our project has encountered a problem that is more troubled. When using ReadFile to download the picture file, the file will be one more than the original (0x0A), using Uedit Delete the first of the file 16 binary files can be read correctly.

The source code is as follows:

PHP Code
  
   
  
   



The downloaded file and the original file are compared as follows:


The code ran on the previous server and never had a problem, but when our project was replaced with a running support environment (the operating system/apache/php version may be different), all the documents were searched on the internet without a workaround. Ask the master to solve this problem, thank you here first!

If there is an effective solution, you will be appended to the 200-knot post.



------Solution--------------------
PHP Code
Give you a piece//$mime, File type//$filename, this needless to say//$data is the file data you want to output, you try file_get_contents to get 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--------------------
Just used your code to test a bit, did not appear you said the question.

Ob_clean ();
Flush ();

Take these two sentences out of the way.
------Solution--------------------
Before your line of code, see if there are output characters??
------Solution--------------------
More line breaks,,, paste the code is not your production environment
------Solution--------------------
The source code is as follows:

[code=php]

$file = ' test_img.bmp ';

It is clear that your The lower level is that you don't even have a BOM head.
  • 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.