`
天梯梦
  • 浏览: 13643995 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

PHP保存Base64图片 Convert Base64 string to an image file

 
阅读更多

The problem is that data:image/png;base64, is included in the encoded contents. This will result in invalid image data when the base64 function decodes it. Remove that data in the function before decoding the string, like so.

function base64_to_jpeg($base64_string, $output_file) {
    $ifp = fopen($output_file, "wb"); 

    $data = explode(',', $base64_string);

    fwrite($ifp, base64_decode($data[1])); 
    fclose($ifp); 

    return $output_file; 
}

 

 

原文:http://stackoverflow.com/a/15153931/4484798

转自:PHP保存Base64图片 Convert Base64 string to an image file

 

分享到:
评论

相关推荐

    imageformats-master.rar

    C# 处理小众图片源码,是从源码库下载 imageformats,放在此是为了自己以后学习方便,希望你也能尽快处理好,我耽误... return Convert.ToBase64String(arr); } catch (Exception e) { return e.ToString(); } }

    php.ini-development

    sets foo to an empty string ; foo = None ; sets foo to an empty string ; foo = "None" ; sets foo to the string 'None' ; If you use constants in your value, and these constants belong to a ; ...

    WPTools.v6.29.1.Pro

    * Delphi XE2: several small changes to provide compatibilty to 64bit compiler (requires WPTools PRO) + new demo developed with Delphi XE2, showcases actions, splitscreen, simulated MDI and property ...

    Senfore_DragDrop_v4.1

    A batch file, convert_forms_to delphi_4_format.bat, is supplied in the demo directory which automates the conversion process. The C++ Builder demo forms are distributed in binary format. 7) If ...

    Bochs - The cross platform IA-32 (x86) emulator

    specify an alternative redolog file of USB MSD disk image modes) - hard drive - new disk image mode 'vvfat' - ported the read-only part of Qemu's 'virtual VFAT' block driver - additions: ...

    Visual C++ 编程资源大全(英文源码 其它)

    05.zip Finding memory leaks 发现内存的泄漏(6KB)<END><br>6,06.zip Convert message ID to a string 将消息标志符转换成字符串(4KB)<END><br>7,07.zip Message Tracer 消息跟踪(5KB)<END><br>8,...

    c# 加密和解密相关代码

    本实例实现时主要用到了string 类的ToCharArray 方法和Convert 类的ToChar 方法,下面分别对它们进行 详细介绍。 (1)string类的ToCharArray 方法 string类的ToCharArray 方法用来将字符串中的字符复制到Unicode ...

    C# for CSDN 乱七八糟的看不懂

    常用 Convert 方法有: 第2页 C#(WINFORM)学习 C# Convert.ToBoolean Convert.ToByte Convert.ToChar Convert.ToDateTime Convert.ToDecimal Convert.ToDouble Convert.ToInt16 Convert.ToInt32 Convert.ToInt64 ...

    ZendFramework中文文档

    1. Introduction to Zend Framework 1.1. 概述 1.2. 安装 2. Zend_Acl 2.1. 简介 2.1.1. 关于资源(Resource) 2.1.2. 关于角色(Role) 2.1.3. 创建访问控制列表(ACL) 2.1.4. 注册角色(Role) 2.1.5. 定义访问...

    c#拼图游戏

    im = Image.FromFile(filename); bm = new Bitmap(320, 320); Graphics gg = Graphics.FromImage(bm); gg.DrawImage(im, new Rectangle(0, 0, 320, 320)); panel2.BackgroundImage = im; pb = new ...

    C#全能速查宝典

    1.1.3 base关键字——从派生类中访问基类的成员 3 1.1.4 变量——存储特定类型的数据 4 1.1.5 Console类——控制台中的输入流、输出流和错误流 6 1.1.6 Convert类——类型转换 8 1.1.7 常量——值不改变的量 9 1.1.8...

Global site tag (gtag.js) - Google Analytics