<?php
$file_dir='tu/'.date("Y/m/d").'/';
$fileName=create_guid();
$storage = new SaeStorage();
$domain = 'uploads';
$destFileName = $file_dir.$fileName;
//$srcFileName = $tempFile;
$attr = array('encoding'=>'gzip'); //保存base64字符串为图片
//匹配出图片的格式
$base64_image_content=$_REQUEST["urls"];
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)){
$type = $result[2];
$ex_file = ".{$type}";
$destFileName=$destFileName.$ex_file;
//echo str_replace($result[1], '', $base64_image_content);
$file_content=base64_decode(str_replace($result[1], '', $base64_image_content));
//$result = $storage->upload($domain,$destFileName,$file_content); $storage->write( $domain , $destFileName , $file_content );
$result=$storage->getUrl($domain,$destFileName);
if(!$result) {
//失败
echo '';
}else{
//成功
echo $result;
}
}else{ echo $base64_image_content; }
function create_guid() {
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$hyphen = chr(45);// "-"
$uuid =''// chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
//.chr(125);// "}"
return $uuid;
}
?>

PHP 将Base64图片保存到 Sae storage的更多相关文章

  1. Android—将Bitmap图片保存到SD卡目录下或者指定目录

    直接上代码就不废话啦 一:保存到SD卡下 File file = new File(Environment.getExternalStorageDirectory(), System.currentT ...

  2. C#中 将图片保存到Sql server 中

    private void Form1_Load(object sender, EventArgs e) { #region 保存数据库 string url = @"C:\Users\Adm ...

  3. Android把图片保存到SQLite中

    1.bitmap保存到SQLite 中 数据格式:Blob db.execSQL("Create table " + TABLE_NAME + "( _id INTEGE ...

  4. Java将头像图片保存到MySQL数据库

    在做头像上传的过程中通常是将图片保存到数据库中,这里简单介绍一中将图片保存到数据库的方法: jsp代码: <div> <input class="avatar-input& ...

  5. python mysql 图片保存到表,从表中读出图片

    fp = open(aa, 'rb') try: img = fp.read() except: print("图片打开出错") fp.close() return img #上面 ...

  6. 以二进制方式读取图片保存到string

    procedure TForm1.BitBtn1Click(Sender: TObject);var  StringStream : TStringStream;  FSize : integer;  ...

  7. android图片保存到SQLlite如何实现?

    //写入数据库               ImageView pic = (ImageView) findViewById(R.id.picture);                        ...

  8. Android 程序drawable资源保存到data目录

    今天做了个小功能,就是把我们程序Drawable里面的图片保存到data目录下面,然后另外一个程序需要读取data目录里面保存的图片.涉及了data目录读写.这功能看上去挺简单,不过实际做的时候还是遇 ...

  9. Android相机、相册获取图片显示并保存到SD卡

    Android相机.相册获取图片显示并保存到SD卡 [复制链接]   电梯直达 楼主    发表于 2013-3-13 19:51:43 | 只看该作者 |只看大图  本帖最后由 happy小妖同学 ...

随机推荐

  1. 为你的网页中添加一些空格&nbsp;

    在上一节的例子,我们已经讲解过在html代码中输入空格.回车都是没有作用的.要想输入空格,必须写入 . 语法:   在html代码中输入空格是不起作用的,如下代码. 在浏览中显示,还是没有空格效果. ...

  2. uvalive 5760 Alice and Bob (组合游戏,dp)

    题目链接: http://vjudge.net/problem/viewProblem.action?id=25636 对于>1的堆,必然会被其中一人全部合并. 然后就是二维dp,dp[非1堆的 ...

  3. Qt信号槽连接在有默认形参下的情况思考

    写下这个给自己备忘,比如函数 ) 你在调用端如论是test(3)或者test(),都可以正确调用到这个函数. 但是,如果放到Qt中的信号槽的话,这个还是值得讲一讲的,不然的话,可能会引起相应的误会. ...

  4. Android学习----五大布局

    1.LinearLayout 线性布局 android:orientation="horizontal" 制定线性布局的排列方式 水平 horizontal 垂直 vertical ...

  5. PHP应用程序的安全性

    无论在开发中,还是在面试时或者技术讨论时,安全性都是需要深入了解及掌握的. 目标 本教程目标是使您了解应该如何保护自己构建的 Web 应用程序.讲解如何防御最常见的安全威胁:SQL 注入.操纵 GET ...

  6. phpstorm 配置

    JetBrains PhpStorm 8注册码一枚 username :cf96PiPYt271u1TC License Key : 97807-12042010 00001GctOKh8f206hl ...

  7. 转:微博"收藏/赞/转发"技术资料汇总

    书籍 HTTP权威指南 <- @Fenng Introduction to Information Retrieval <- @陈利人 Lua 源码欣赏 <- @简悦云风 The A ...

  8. Sleep的问题

    先上全部源码: using System; using System.Threading; namespace MoveServices { public static class MoveWorke ...

  9. -_-#【React】

    React Native 用于构建用户界面的JAVASCRIPT库 | ReactReact 入门实例教程颠覆式前端UI开发框架:Reactzhihu1zhihu2 React.js编程思想 < ...

  10. 使用C#开发ActiveX控件 11

    C#开发ActiveX控件   ActiveX 是一个开放的集成平台,为开发人员.用户和 Web生产商提供了一个快速而简便的在 Internet 和 Intranet 创建程序集成和内容的方法. 使用 ...