Image Storage-Use PHP to save the image while keeping the md5 value of the source Image

Source: Internet
Author: User
The source image has the same md5 value as the source image obtained by curl, but it cannot be obtained after fwrite in php. ask sf's friends: how to use it... when using php to download images, the source Image http://su.bdimg.com/static/superplus/img/logo_white_ee663702.pngDownload,
The source image is the same as the md5 value obtained by curl, but it cannot be obtained after fwrite in php.

QuestionFriends of sf: how to keep the md5 value unchanged when saving images with PHP!

The Code is as follows:

/*** Load the image **/$ save_dir = APP. 'tmp '. DS; $ url = 'HTTP: // su.bdimg.com/static/superplus/img/logo_white_ee663702.png'{img = http_client_request ($ url); the MD5 value of the binary stream file obtained by echo 'curl:
'. Md5 ($ img); // comment ', 'A'); fwrite ($ fp2, $ img); fclose ($ fp2); unset ($ img, $ url ); echo "\ n"; $ fmd5 = 'Save the image MD5 using fwrite:
'.Md5_file(inclusave_dir.'baidu-save.png '); echo $ fmd5; echo 'source image md5:
'.Md5_file(inclusave_dir.'baidu-org.png ');

The result is as follows:

The MD5 value of the binary stream file obtained by Curl:
329b15e8ba7234317dc663f8ee663702
Use fwrite to save image MD5:
D477312948ef7bd72c4209b8db707f68
Source image md5:
329b15e8ba7234317dc663f8ee663702

Reply content:

When using php to download images, the source Imagehttp://su.bdimg.com/static/superplus/img/logo_white_ee663702.pngDownload,
The source image is the same as the md5 value obtained by curl, but it cannot be obtained after fwrite in php.

QuestionFriends of sf: how to keep the md5 value unchanged when saving images with PHP!

The Code is as follows:

/*** Load the image **/$ save_dir = APP. 'tmp '. DS; $ url = 'HTTP: // su.bdimg.com/static/superplus/img/logo_white_ee663702.png'{img = http_client_request ($ url); the MD5 value of the binary stream file obtained by echo 'curl:
'. Md5 ($ img); // comment ', 'A'); fwrite ($ fp2, $ img); fclose ($ fp2); unset ($ img, $ url ); echo "\ n"; $ fmd5 = 'Save the image MD5 using fwrite:
'.Md5_file(inclusave_dir.'baidu-save.png '); echo $ fmd5; echo 'source image md5:
'.Md5_file(inclusave_dir.'baidu-org.png ');

The result is as follows:

The MD5 value of the binary stream file obtained by Curl:
329b15e8ba7234317dc663f8ee663702
Use fwrite to save image MD5:
D477312948ef7bd72c4209b8db707f68
Source image md5:
329b15e8ba7234317dc663f8ee663702

Is it because it already exists?baidu-save.png, And thenfopenParameters Used'a'So it is added to the end.
Change'w'Or'wb'Try.

xxd logo_white_ee663702.png > logo_white_ee663702.hexxxd baidu-save.png > baidu-save.hexdiff logo_white_ee663702.hex baidu-save.hex

Fwrite ($ fp2, 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.