PHP implements the method of saving Base64 format pictures in the specified directory _php tips

Source: Internet
Author: User
Tags base64

The example in this article describes how the PHP implementation saves the Base64 format picture in the specified directory. Share to everyone for your reference, specific as follows:

<?php
Header (' Content-type:text/html;charset=utf-8 ');
$base 64_image_content = $_post[' imgBase64 '];
Match the format of the picture
if (Preg_match (data:\s*image\/(\w+); base64,)/', $base 64_image_content, $result)) {
$type = $ RESULT[2];
$new _file = "upload/active/img/". Date (' Ymd ', Time ()). " /";
if (!file_exists ($new _file))
{
//check if there is a folder, create it if not, and give the highest permission
mkdir ($new _file, 0700);
}
$new _file = $new _file.time (). ". {$type} ";
if (file_put_contents ($new _file, Base64_decode (Str_replace ($result [1], ', $base 64_image_content))) {
echo ' New File Save success: ', $new _file;
} else{
Echo ' new file save failed ';
}
? >

PS: Here again for you to recommend several online picture Tools for everyone to use the reference

Picture converted to BASE64 encoded online tool:
Http://tools.jb51.net/transcoding/img2base64

Online Email Email icon Production tool:
Http://tools.jb51.net/email/emaillogo

Online PS image processing tools:
http://tools.jb51.net/aideddesign/webps

Online picture format conversion (jpg/bmp/gif/png) Tool:
Http://tools.jb51.net/aideddesign/picext

ico icon Online generation tool:
Http://tools.jb51.net/aideddesign/ico_img

For more information on PHP related content readers can view the site topics: "PHP graphics and pictures Operating skills summary", "Basic PHP Grammar Introductory Course", "PHP Operations and Operator Usage Summary", "PHP object-oriented Program Design Introductory Course", "PHP Network Programming Skills Summary", "PHP array (Array) Operations tips Encyclopedia, "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP Common database Operation tips Summary"

I hope this article will help you with the PHP program design.

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.