PHP read the picture, read the bytes more than the actual bytes of the picture, read carefully the PHP manual self-Thinking code is no problem
My code is as follows:
$filepath = "C:\123.jpg";
$filesize =filesize ($filepath);
$fs =fopen ($filepath, "R");
$readlen =1024;//How many bytes per read
How many bytes are read $rlen =0;//
while (!feof ($FS)) {
$data =fread ($fs, $readlen);
$rlen + = $readlen;
}
Fclose ($FS);
echo ' File Size '. $filesize. '
';
echo ' read size '. $rlen. '
';
?>
PHP friends to see, My Computer system Windows 7, which should not be related to the system.
------Solution--------------------
This is exactly the system!
Window's file opening method has the difference between the text way and the binary way
In text mode, a \ r is attached to each \ n (not \ r \ n combination), forming \ r \ n
So the number of bytes is more.
You need to use binary to prevent images from being opened
$fs =fopen ($filepath, "R b");
or directly with file_get_contents.