Use PHP to download pictures when encountering MD5 problems, the source image through
http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png
Download
The original image and curl get the same MD5 as the picture source, but not after using the fwrite in PHP.
Ask SF friends: How to save the picture in PHP when the MD5 value is not changed!
Code such as:
/*** 加载图片* */$save_dir = APP.'tmp'.DS;$url = 'http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png';$img = http_client_request( $url );echo 'Curl获取的二进制流文件MD5值:
'.md5($img); //图片md5$fp2=@fopen($save_dir.'baidu-save.png','a');fwrite($fp2,$img);fclose($fp2);unset($img,$url);echo "\n";$fmd5 = '通过fwrite保存图片MD5:
'.md5_file($save_dir.'baidu-save.png');echo $fmd5;echo '原图md5:
'.md5_file($save_dir.'baidu-org.png');
Results such as:
Curl gets the binary stream file MD5 value:
329b15e8ba7234317dc663f8ee663702
Save Picture MD5 by Fwrite:
d477312948ef7bd72c4209b8db707f68
Original MD5:
329b15e8ba7234317dc663f8ee663702
Reply content:
Use PHP to download pictures when encountering MD5 problems, the source image by http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png
downloading,
The original image and curl get the same MD5 as the picture source, but not after using the fwrite in PHP.
Ask SF friends: How to save the picture in PHP when the MD5 value is not changed!
Code such as:
/*** 加载图片* */$save_dir = APP.'tmp'.DS;$url = 'http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png';$img = http_client_request( $url );echo 'Curl获取的二进制流文件MD5值:
'.md5($img); //图片md5$fp2=@fopen($save_dir.'baidu-save.png','a');fwrite($fp2,$img);fclose($fp2);unset($img,$url);echo "\n";$fmd5 = '通过fwrite保存图片MD5:
'.md5_file($save_dir.'baidu-save.png');echo $fmd5;echo '原图md5:
'.md5_file($save_dir.'baidu-org.png');
Results such as:
Curl gets the binary stream file MD5 value:
329b15e8ba7234317dc663f8ee663702
Save Picture MD5 by Fwrite:
d477312948ef7bd72c4209b8db707f68
Original MD5:
329b15e8ba7234317dc663f8ee663702
Is it because it already exists baidu-save.png
, then fopen
uses the parameter 'a'
, then adds to the tail.
Change 'w'
or try 'wb'
.
xxd logo_white_ee663702.png > logo_white_ee663702.hexxxd baidu-save.png > baidu-save.hexdiff logo_white_ee663702.hex baidu-save.hex
Fwrite ($fp 2,md5 ($img));