PHP 将Base64图片保存到 Sae storage
<?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的更多相关文章
- Android—将Bitmap图片保存到SD卡目录下或者指定目录
直接上代码就不废话啦 一:保存到SD卡下 File file = new File(Environment.getExternalStorageDirectory(), System.currentT ...
- C#中 将图片保存到Sql server 中
private void Form1_Load(object sender, EventArgs e) { #region 保存数据库 string url = @"C:\Users\Adm ...
- Android把图片保存到SQLite中
1.bitmap保存到SQLite 中 数据格式:Blob db.execSQL("Create table " + TABLE_NAME + "( _id INTEGE ...
- Java将头像图片保存到MySQL数据库
在做头像上传的过程中通常是将图片保存到数据库中,这里简单介绍一中将图片保存到数据库的方法: jsp代码: <div> <input class="avatar-input& ...
- python mysql 图片保存到表,从表中读出图片
fp = open(aa, 'rb') try: img = fp.read() except: print("图片打开出错") fp.close() return img #上面 ...
- 以二进制方式读取图片保存到string
procedure TForm1.BitBtn1Click(Sender: TObject);var StringStream : TStringStream; FSize : integer; ...
- android图片保存到SQLlite如何实现?
//写入数据库 ImageView pic = (ImageView) findViewById(R.id.picture); ...
- Android 程序drawable资源保存到data目录
今天做了个小功能,就是把我们程序Drawable里面的图片保存到data目录下面,然后另外一个程序需要读取data目录里面保存的图片.涉及了data目录读写.这功能看上去挺简单,不过实际做的时候还是遇 ...
- Android相机、相册获取图片显示并保存到SD卡
Android相机.相册获取图片显示并保存到SD卡 [复制链接] 电梯直达 楼主 发表于 2013-3-13 19:51:43 | 只看该作者 |只看大图 本帖最后由 happy小妖同学 ...
随机推荐
- python自学笔记
python自学笔记 python自学笔记 1.输出 2.输入 3.零碎 4.数据结构 4.1 list 类比于java中的数组 4.2 tuple 元祖 5.条件判断和循环 5.1 条件判断 5.2 ...
- mktime性能问题
#include <time.h> int main() { for (int i = 0; i < 100000; ++i) { struct tm tm = {}; tm.tm_ ...
- Build Android-x86 ICS 4 Virtualbox from Google Virtualbox Target and Intel Kernel 编译体验
最近一直在研究android源码的编译,应该说研究的很辛苦,最难的是下源码,总是不停的断掉,最后感谢公司的高网速,找到方法后12G的源码只花了1个小时就下完了. 参考以下网址:http://softw ...
- table表格cellspacing与cellpadding属性
cellspacing属性 用来指定表格各单元格之间的空隙. cellpadding属性 用来指定单元格内容与单元格边界之间的空白距离的大小. 此属性的参数值也是数字,表示单元格内容与上下边界之间空白 ...
- ecshop里Ajax.call()方法定义
Ajax.call()在哪个文件中定义的? 在加载的js/transport.js文件里面. Ajax.cal()方法就是Transport.run()方法
- 欧几里德算法gcd及其拓展终极解释
这个困扰了自己好久,终于找到了解释,还有自己改动了一点点,耐心看完一定能加深理解 扩展欧几里德算法-求解不定方程,线性同余方程. 设过s步后两青蛙相遇,则必满足以下等式: (x+m*s)-(y+n ...
- ATR的基本结构与意义(无历史字符部分)
Reset 3B FA 13 00 00 81 31 FE 45 4A 43 4F 50 34 31 56 32 32 31 96 复位应答 ATR TS( The Initial character ...
- Linux定时运行与开机运行任务
http://os.51cto.com/art/200805/75144.htm at命令与crontab命令 http://os.51cto.com/art/201007/211874.htm ht ...
- Java获取程序或项目路径的常用方法
在写java程序时不可避免要获取文件的路径,比较常用的方法有: 1 在任意的class里调用: this.getClass().getClassLoader().getResource("/ ...
- Buy the Ticket HDU 1133 递推+大数
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元, m个人是只有50元一张的, n个人 ...