PHP reads an image and reads more bytes than the actual bytes. after carefully studying the PHP manual, I think the Code is okay. my Code is as follows: & lt ;? Php & nbsp; $ filepathc: 123.jpg; & nbsp; $ filesizefilesize ($ filepath); & nbsp; $ fsfopen ($ filepath PHP reads an image in bytes more than the actual number of bytes in the image. after carefully studying the PHP manual, I think the code is okay.
My Code is as follows:
$ Filepath = "c: \ 123.jpg ";
$ Filesize = filesize ($ filepath );
$ Fs = fopen ($ filepath, "r ");
$ Readlen = 1024; // The number of bytes read each time.
$ Rlen = 0; // The total number of bytes read.
While (! Feof ($ fs )){
$ Data = fread ($ fs, $ readlen );
$ Rlen + = $ readlen;
}
Fclose ($ fs );
Echo 'file size'. $ filesize .'
';
Echo 'read size'. $ rlen .'
';
?>
PHP friends to show, my computer system windows 7, this should have nothing to do with the system.
------ Solution --------------------
This is precisely related to the system!
Window files are opened in the text and binary modes.
In text mode, an \ r is appended to each \ n (not a \ r \ n combination) to form \ r \ n
So the number of bytes is increased.
You need to use binary to prevent Image opening
$ Fs = fopen ($ filepath, "rb ");
Or use file_get_contents directly.