Picture Store-Save the image using PHP while keeping the MD5 value of the source image

Source: Internet
Author: User
Use PHP to download pictures when encountering MD5 problems, the source image through http://su.bdimg.com/static/superplus/img/logo_white_ee663702.pngDownload
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));

  • 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.