本文整理汇总了PHP中SaeStorage::write方法的典型用法代码示例。如果您正苦于以下问题:PHP SaeStorage::write方法的具体用法?PHP SaeStorage::write怎么用?PHP SaeStorage::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SaeStorage
的用法示例。
在下文中一共展示了SaeStorage::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SaeStorage
function is_storage_ok()
{
$s = new SaeStorage();
$status = $s->write('public', '.dilicms_install_test', '');
$status and $s->delete('public', '.dilicms_install_test');
return $status;
}
示例2: putFileContent
public static function putFileContent($filename, $content)
{
if (OpenConfig::SAE_MODE) {
$s = new SaeStorage();
$s->write(OpenConfig::SAE_DOMAIN, $filename, $content);
} else {
$data = file_put_contents($filename, $content);
}
}
示例3: SaeStorage
function s_write($path, $content)
{
if (IS_SAE) {
$_s = new SaeStorage();
$_f = _s_get_path($path);
return $_s->write($_f['domain'], $_f['filename'], $content);
} else {
return file_put_contents($path, $content);
}
}
示例4: SaeStorageAppend
function SaeStorageAppend($FilePath, $AppendContent)
{
$storage = new SaeStorage();
$domain = Sae_Storage_Domain_Name;
$result = $storage->read($domain, $FilePath);
if ($result === false) {
return false;
}
$FileContent = $result . $AppendContent;
$size = -1;
//长度限制
//$attr = array('encoding'=>'gzip');//文件属性(gzip压缩)
//$compress = true;//文件是否gzip压缩
$attr = array();
$compress = false;
$result = $storage->write($domain, $FilePath, $FileContent, $size, $attr, $compress);
return $result;
}
示例5: thumb
public static function thumb($image, $thumbname, $domain = 'public', $maxWidth = 200, $maxHeight = 50, $interlace = true)
{
// 获取原图信息
$info = self::getImageInfo($image);
if ($info !== false) {
$srcWidth = $info['width'];
$srcHeight = $info['height'];
$type = strtolower($info['type']);
$interlace = $interlace ? 1 : 0;
unset($info);
$scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
// 计算缩放比例
if ($scale >= 1) {
// 超过原图大小不再缩略
$width = $srcWidth;
$height = $srcHeight;
} else {
// 缩略图尺寸
$width = (int) ($srcWidth * $scale);
$height = (int) ($srcHeight * $scale);
}
//sae平台上图片处理
if (class_exists('SaeStorage')) {
$saeStorage = new SaeStorage();
$saeImage = new SaeImage();
$saeImage->setData(file_get_contents($image));
$saeImage->resize($width, $height);
$thumbname = str_replace(array('../', './'), '', $thumbname);
return $saeStorage->write($domain, $thumbname, $saeImage->exec());
}
// 载入原图
$createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
$srcImg = $createFun($image);
//创建缩略图
if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
$thumbImg = imagecreatetruecolor($width, $height);
} else {
$thumbImg = imagecreate($width, $height);
}
// 复制图片
if (function_exists("ImageCopyResampled")) {
imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
} else {
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
}
if ('gif' == $type || 'png' == $type) {
$background_color = imagecolorallocate($thumbImg, 0, 255, 0);
// 指派一个绿色
imagecolortransparent($thumbImg, $background_color);
// 设置为透明色,若注释掉该行则输出绿色的图
}
// 对jpeg图形设置隔行扫描
if ('jpg' == $type || 'jpeg' == $type) {
imageinterlace($thumbImg, $interlace);
}
$dir = dirname($thumbname);
if (!is_dir($dir)) {
@mkdir($dir, 0777, true);
}
// 生成图片
$imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
$imageFun($thumbImg, $thumbname);
imagedestroy($thumbImg);
imagedestroy($srcImg);
return $thumbname;
}
return false;
}
示例6: define
static function upload_topic($pic_name, $change = 0, $oldpic = null)
{
define('DOMAIN', 'upload');
//要上传的storage名称定义
$temp = 'temp';
$s = new SaeStorage();
$poc = array('_big.jpg', '_midde.jpg', '_small.jpg', '.jpg');
foreach ($poc as $p) {
$pic = $pic_name . $p;
$img = $s->read($temp, $pic);
if ($s->write(DOMAIN, $pic, $img) == false) {
echo "图片写入失败!请重新上传,如果还是失败请联系客服!但是不要放弃对咱们原创的希望";
var_dump($s->errno(), $s->errmsg());
}
unset($pic);
unset($pics);
unset($img);
}
self::delete_topic($pic_name);
if ($change == 1) {
self::delete_topic($oldpic, 'jpg', 'upload');
}
unset($s);
return 1;
}
示例7: strlen
for ($i = 0; $i < 5; $i++) {
$b = $kv->set('servers', $newfile);
if ($b) {
break;
}
}
$tlen = $len = strlen($newfile);
if ($tlen > 200 - $oflen) {
$tlen = 200 - $oflen;
}
$servers = substr($newfile, 0, $tlen);
$servers = $version . $official . $servers;
require 'settings.php';
$storage = new SaeStorage($access_key, $secret_key);
for ($i = 0; $i < 5; $i++) {
$b = $storage->write($domain, 'servers', $servers);
if ($b) {
break;
}
}
if ($len > 200 - $oflen) {
$full = substr($newfile, 200 - $oflen);
$full = $version . $full;
for ($i = 0; $i < 5; $i++) {
$b = $storage->write($domain, 'full', $full);
if ($b) {
break;
}
}
}
echo '0';
示例8: put
/**
*
* {@inheritDoc}
* @see \Illuminate\Contracts\Filesystem\Filesystem::put()
*/
public function put($path, $contents, $visibility = null)
{
list($domain, $path) = $this->parser($path);
return $this->storage->write($domain, $path, $contents);
}
示例9: cropAvatar
private function cropAvatar($path, $crop = null)
{
//如果不裁剪,则发生错误
if (!$crop) {
$this->error = '必须裁剪';
return false;
}
//是sae则不需要获取全路径
if (strtolower(APP_MODE) != 'sae') {
//本地环境
//获取头像的文件路径
$fullPath = $this->getFullPath($path);
//生成文件名后缀
$postfix = substr(md5($crop), 0, 8);
$savePath = preg_replace('/\\.[a-zA-Z0-9]*$/', '-' . $postfix . '$0', $fullPath);
$returnPath = preg_replace('/\\.[a-zA-Z0-9]*$/', '-' . $postfix . '$0', $path);
//解析crop参数
$crop = explode(',', $crop);
$x = $crop[0];
$y = $crop[1];
$width = $crop[2];
$height = $crop[3];
//载入临时头像
$image = ImageWorkshop::initFromPath($fullPath);
//如果宽度和高度近似相等,则令宽和高一样
if (abs($height - $width) < $height * 0.01) {
$height = min($height, $width);
$width = $height;
} else {
$this->error = $height . '图像必须为正方形';
return false;
}
//确认头像足够大
if ($height < 256) {
$this->error = '头像太小';
return false;
}
//调用组件裁剪头像
$image = ImageWorkshop::initFromPath($fullPath);
$image->crop(ImageWorkshopLayer::UNIT_PIXEL, $width, $height, $x, $y);
$image->save(dirname($savePath), basename($savePath));
//返回新文件的路径
return $returnPath;
} else {
//sae
$fullPath = $path;
$postfix = substr(md5($crop), 0, 8);
$savePath = preg_replace('/\\.[a-zA-Z0-9]*$/', '-' . $postfix . '$0', $fullPath);
$returnPath = preg_replace('/\\.[a-zA-Z0-9]*$/', '-' . $postfix . '$0', $path);
//解析crop参数
$crop = explode(',', $crop);
$x = $crop[0];
$y = $crop[1];
$width = $crop[2];
$height = $crop[3];
//载入临时头像
$f = new \SaeFetchurl();
$img_data = $f->fetch($fullPath);
$img = new \SaeImage();
$img->setData($img_data);
$img_attr = $img->getImageAttr();
//生成将单位换算成为像素
$x = $x * $img_attr[0];
$y = $y * $img_attr[1];
$width = $width * $img_attr[0];
$height = $height * $img_attr[1];
//如果宽度和高度近似相等,则令宽和高一样
if (abs($height - $width) < $height * 0.01) {
$height = min($height, $width);
$width = $height;
} else {
$this->error = '图像必须为正方形';
return false;
}
//确认头像足够大
if ($height < 128) {
$this->error = '头像太小';
return false;
}
/* dump('x='.$x);
dump('y='.$y);
dump('w='.$width);
dump('h='.$height);exit;*/
$img->crop($x / $img_attr[0], ($x + $width) / $img_attr[0], $y / $img_attr[1], ($y + $height) / $img_attr[1]);
$new_data = $img->exec();
$storage = new \SaeStorage();
$thumbFilePath = str_replace(C('UPLOAD_SAE_CONFIG.rootPath'), '', dirname($savePath) . '/' . basename($savePath));
$thumbed = $storage->write(C('UPLOAD_SAE_CONFIG.domain'), $thumbFilePath, $new_data);
//返回新文件的路径
return $thumbed;
}
}
示例10: info
}
if ($t) {
$data = '该用户名已被注册,请重新输入';
} else {
if ($u) {
$mysql->runSql("UPDATE info SET alias='{$alias}' WHERE FromUserName='{$openid}'");
$data = '更改成功!';
} else {
$mysql->runSql("INSERT INTO info(FromUserName,alias) VALUES ('{$openid}','{$alias}')");
$data = '注册成功!';
}
}
} elseif (preg_match('#(/:)#i', $content)) {
$data = $biaoqing[rand(0, count($biaoqing) - 1)];
} elseif (preg_match('#^(simi:)(.+)#i', $content, $matches)) {
$s->write('simsimi', 'simi.txt', $matches[2]);
$data = '更改成功!';
} elseif ($content == 'stack') {
$res = stackoverflow();
$data = array(array('title' => 'Stack Overflow', 'cover' => $web . '/img/meizi/' . mt_rand(0, 9) . '.jpg'));
for ($i = 0; $i < count($data); $i++) {
if ($res[$i]) {
array_push($data, array('title' => str_replace('-', ' ', $res[$i]['title']), 'note' => 'votes:' . $res[$i]['vote'] . ' answers:' . $res[$i]['answer'] . ' views:' . $res[$i]['view'], 'link' => 'http://stackoverflow.com/questions/' . $res[$i]['id']));
}
}
} elseif (preg_match('#^(md5:)(.+)#i', $content, $matches)) {
$data = md5($matches[2]);
} elseif ($content == 'bilibili') {
$res = bilibili();
$data = array(array('title' => 'Bilibili', 'cover' => $web . '/img/bili/' . mt_rand(0, 10) . '.jpg'));
for ($i = 0; $i < count($data); $i++) {
示例11: matchEngine
function matchEngine($content)
{
global $reg_arr, $biaoqing;
foreach ($reg_arr as $key => $value) {
if (preg_match($key, $content, $matches)) {
switch ($value) {
case 'dream':
$data = dream($matches[2]);
break;
case 'translate':
$data = translateAPI($matches[2]);
break;
case 'biaoqing':
$data = $biaoqing[rand(0, count($biaoqing) - 1)];
break;
case 'changeSimsimiKey':
$s = new SaeStorage();
$s->write('simsimi', 'simi.txt', $matches[2]);
$data = '更改成功!';
break;
case 'md5':
$data = md5($matches[2]);
break;
case 'qrcode':
$qrcode = 'http://chart.apis.google.com/chart?cht=qr&chs=400x400&choe=UTF-8&chl=' . $matches[2];
$data = array(array('title' => $matches[2], 'cover' => $qrcode, 'link' => $qrcode));
break;
case 'bingSearch':
$bingweb = bing($matches[2], 'Web');
$bingimage = bing($matches[2], 'Image');
$data = array(array('title' => $matches[2], 'note' => '', 'cover' => $bingimage[0], 'link' => ''));
//max:7
for ($i = 0; $i < 5; $i++) {
array_push($data, array('title' => $bingweb[$i]['title'] . "\n" . '------------------------------------------', 'note' => $bingweb[$i]['description'], 'cover' => '', 'link' => $bingweb[$i]['url']));
}
break;
case 'wiki':
$wiki = wiki($matches[2], $lng);
$data = array();
for ($i = 0; $i < 5; $i++) {
array_push($data, array('title' => $wiki[$i]['title'] . "\n" . '------------------------------------------', 'note' => $wiki[$i]['snippet'], 'cover' => '', 'link' => 'http://zh.wikipedia.org/wiki/' . $wiki[$i]['title']));
}
break;
case 'doubanMovie1':
$m = doubanMovies($matches[2]);
$data = array(array('title' => $m[0]['title'], 'note' => $m[0]['year'] . ' ' . $m[0]['average'], 'cover' => $m[0]['images']->large, 'link' => $m[0]['alt']));
for ($i = 1; $i <= 5; $i++) {
array_push($data, array('title' => $m[$i]['title'], 'note' => '又名:' . $m[$i]['original_title'] . "\n" . '上映日期:' . $m[$i]['year'] . "\n" . '评价:' . $m[$i]['average'], 'cover' => $m[$i]['images']->small, 'link' => $m[$i]['alt']));
}
break;
case 'doubanMovie2':
$m = doubanMovies($matches[2]);
$movie = doubanMovie($m[0]['id']);
$xinxi = '又名:';
foreach ($movie['aka'] as $value) {
$xinxi .= $value . '/';
}
$xinxi .= "\n" . '上映日期:' . $movie['year'] . "\n" . '制片国家:';
foreach ($movie['countries'] as $value) {
$xinxi .= $value . '/';
}
$xinxi .= "\n" . '类型:';
foreach ($movie['genres'] as $value) {
$xinxi .= $value . '/';
}
$xinxi .= "\n" . '评价:' . $movie['average'];
$data = array(array('title' => $movie['title'], 'cover' => $movie['images'], 'link' => $movie['mobile_url']), array('note' => $xinxi, 'link' => $movie['mobile_url']), array('title' => '简介', 'note' => $movie['summary'], 'link' => $movie['mobile_url']), array('title' => '导演', 'note' => $movie['directors'][0]->name, 'cover' => $movie['directors'][0]->avatars->small, 'link' => $movie['directors'][0]->alt), array('title' => '主演', 'note' => $movie['casts'][0]->name, 'cover' => $movie['casts'][0]->avatars->small, 'link' => $movie['casts'][0]->alt));
break;
case 'doubanBook1':
$b = doubanBooks($matches[2]);
$data = array(array('title' => $b[0]['title'], 'note' => $b[0]['author'][0] . ' ' . $b[0]['average'], 'cover' => $b[0]['images']->large, 'link' => $b[0]['alt']));
for ($i = 1; $i <= 4; $i++) {
array_push($data, array('title' => $b[$i]['title'], 'note' => '作者:' . $b[$i]['author'][0] . "\n" . '出版社:' . $b[$i]['publisher'] . "\n" . '出版日期:' . $b[$i]['pubdate'] . "\n" . '价格:' . $b[$i]['price'] . "\n" . '评价:' . $b[$i]['average'] . "\n" . '导言:' . $b[$i]['summary'], 'cover' => $b[$i]['images']->small, 'link' => $b[$i]['alt']));
}
break;
case 'doubanBook2':
$b = doubanBooks($matches[2]);
$bk = doubanBook($b[0]['id']);
$data = array(array('title' => $bk['title'], 'cover' => $bk['images'], 'link' => $bk['alt']), array('note' => '作者:' . $bk['author'][0] . "\n" . '出版社:' . $bk['publisher'] . "\n" . '出版日期:' . $bk['pubdate'] . "\n" . '价格:' . $bk['price'] . "\n" . '评价:' . $bk['average'], 'link' => $bk['alt']), array('title' => '导言:', 'note' => $bk['summary'], 'link' => $bk['alt']));
break;
case 'doubanMusic1':
$m = doubanMusics($matches[2]);
$data = array(array('title' => $m[0]['title'], 'note' => $m[0]['average'], 'cover' => $m[0]['image'], 'link' => $m[0]['alt']));
for ($i = 1; $i <= 4; $i++) {
array_push($data, array('title' => $m[$i]['title'], 'note' => '作者:' . $m[$i]['author'][0]->name . "\n" . '出版社:' . $m[$i]['publisher'][0] . "\n" . '出版日期:' . $m[$i]['pubdate'][0] . "\n" . '表演者:' . $m[$i]['singer'][0] . "\n" . '评价:' . $m[$i]['average'] . "\n" . '类型:' . $m[$i]['version'][0], 'cover' => $m[$i]['image'], 'link' => $m[$i]['alt']));
}
break;
case 'doubanMusic2':
$m = doubanMusics($matches[2]);
$mu = doubanMusic($m[0]['id']);
$data = array(array('title' => $mu['title'], 'cover' => $mu['image'], 'link' => $mu['mobile_link']), array('note' => '表演者:' . $mu['singer'][0] . "\n" . '专辑类型:' . $mu['version'][0] . "\n" . '发行时间:' . $mu['pubdate'][0] . "\n" . '作者:' . $mu['author'][0]->name . "\n" . '出版者:' . $mu['publisher'][0] . "\n" . '评价:' . $mu['average'], 'link' => $mu['mobile_link']), array('title' => '简介:', 'note' => $mu['summary'], 'link' => $mu['mobile_link']));
break;
case 'moments1':
$moment = $matches[2];
$time = time();
$date = date("Y-m-d H:i:s", time());
$mysql = new SaeMysql();
$res = $mysql->getData("SELECT alias FROM info WHERE FromUserName='{$openid}'");
$alias = $res[0]['alias'];
if (!$alias) {
//.........这里部分代码省略.........
示例12: SaeStorage
function s_write($filepath, $content)
{
$_s = new SaeStorage();
//初始化Storage对象
$_f = _s_get_path($filepath);
return $_s->write($_f['domain'], $_f['filename'], $content);
}
示例13: save
/**
* 将图片资源保存到storage
* @returns string storage中图片的URL
*/
public function save()
{
//给文件名添加随机的后缀,防止重复
$random = mt_rand();
$filename = substr(str_replace("/", "", parse_url($this->url, PHP_URL_PATH)), -10) . $random . ".jpg";
//just for test
//$stor = new SaeStorage("n353jmy031","zwwkm3wjxmmkxkhwzlyjhxz3lh2xkyj3zhx014lh");
/* imagepng这样的函数不支持wrapper,用临时文件解决
imageX 第二个参数指定filename,将文件保存到一个地址而不是输出到浏览器
使用sae storage的wrapper来保存图片
file_put_contents("saestor://n/test.txt", "haha");
保存为临时文件
$bool = imagejpeg($img, SAE_TMP_PATH . $filename);
imagedestroy($img);
$this-log("保存的文件名:" . $filename);
从临时文件里取出,保存到storage里
file_put_contents("saestor://wechatimg/$filename",
file_get_contents(SAE_TMP_PATH . $filename));*/
/*
* 新的文件保存方法 用缓存来实现,这个方法应该会快很多,因为减少了两个特别慢的函数
*/
$domain = "wechatimg";
$stor = new SaeStorage();
ob_start();
imagejpeg($this->img);
$imgstr = ob_get_contents();
$bool = $stor->write($domain, $filename, $imgstr);
ob_end_clean();
imagedestroy($this->img);
if (!$bool) {
$this->log("保存文件失败");
}
$this->newUrl = $stor->getUrl($domain, $filename);
return $this->newUrl;
}
示例14: exit_status
$logo_ten_year_img = file_get_contents('../res/images/logo_ten_year110.png');
$logo_zfb_img = file_get_contents('../res/images/logo_zfb100.png');
$text_bg_img = file_get_contents('../res/images/text_back350.png');
//清空$img数据
$img->clean();
//设定要用于合成的三张图片(如果重叠,排在后面的图片会盖住排在前面的图片)
$img->setData(array(array($new_data, 0, 0, 1, SAE_TOP_LEFT), array($logo_ten_year_img, -10, 10, 1, SAE_BOTTOM_RIGHT), array($logo_zfb_img, -10, -10, 1, SAE_TOP_RIGHT), array($text_bg_img, 0, -47, 1, SAE_TOP_LEFT)));
//执行合成
$img->composite($size[0], $size[1]);
//输出图片
$new_data = $img->exec('jpg');
if ($new_data === false) {
exit_status('error', 'p2:' . $img->errmsg());
}
$s = new SaeStorage();
$result = $s->write('rank', $file_name, $new_data);
if (!$result) {
exit_status('fail', $result);
}
$url = $s->getUrl('rank', $file_name);
exit_status('ok', $url);
} else {
exit_status('fail', 'no file accept!');
}
// Helper functions
function exit_status($status, $data)
{
echo json_encode(array('status' => $status, 'data' => $data));
exit;
}
function get_extension($file_name)
示例15: user_update_avatar
/**
* 用户更新头像
*
* 使用标准Form表单上传,头像文件名为file,只接受jpg格式的文件
*
* @param string token , 必填
* @return user array
* @author EasyChen
*/
public function user_update_avatar()
{
if ($_FILES['file']['error'] != 0) {
return self::send_error(OP_API_UPLOAD_ERROR, 'UPLOAD ERROR ' . $_FILES['file']['error']);
}
$tmp_image_name = SAE_TMP_PATH . md5(time() . rand(1, 99999)) . '.tmp.jpg';
jpeg_up($_FILES['file']['tmp_name'], $tmp_image_name);
include_once AROOT . 'lib/thumbnail.class.php';
$file_thumb_name = 'avatar-' . uid() . '.jpg';
$tmp_file = SAE_TMP_PATH . $file_thumb_name;
include_once AROOT . 'lib/icon.class.php';
$icon = new Icon();
$icon->path = $tmp_image_name;
$icon->size = 100;
$icon->dest = $tmp_file;
$icon->createIcon();
if (on_sae()) {
$s = new SaeStorage();
if (!($thumb_url = $s->write('upload', $file_thumb_name, file_get_contents($tmp_file)))) {
return self::send_error(OP_API_STORAGE_ERROR, 'SAVE ERROR ' . $s->errmsg());
}
} else {
$local_storage = AROOT . 'static' . DS . 'upload' . DS . 'avatar' . DS;
$local_storage_url = c('site_url') . DS . 'static' . DS . 'upload' . DS . 'avatar' . DS;
$thumb_path = $local_storage . $file_thumb_name;
$thumb_url = $local_storage_url . $file_thumb_name;
if (!copy($tmp_file, $thumb_path)) {
return self::send_error(OP_API_STORAGE_ERROR, 'SAVE ERROR ');
}
}
$sql = "UPDATE `user` SET `avatar_small` = '" . s($thumb_url) . "' WHERE `id` = '" . intval(uid()) . "' LIMIT 1";
run_sql($sql);
if (mysql_errno() != 0) {
return self::send_error(OP_API_DB_ERROR, __('API_MESSAGE_DATABASE_ERROR') . mysql_error());
} else {
return self::send_result(get_user_info_by_id(intval(uid())));
}
}