sae php 读,sae storage:在PHP中使用Sina Sae提供的_php

本博客使用kindeditor4作为后台文章编辑和发布,kindeditor下载包中有关于php上传文件的实例,直接利用里面的例子就可以实现本地文件上传到服务器磁盘上,但是由于sina sae不允许磁盘操作,所以使用storage API进行上传文件的操作,并将ke中的upload_json.php文件中关于磁盘操作的所有代码注释,采用storage API,我最后的代码如下所示:

/**

* KindEditor PHP

*

http://www.gaodaima.com/50791.htmlsae storage:在PHP中使用Sina Sae提供的_php

* 本PHP程序是演示程序,建议不要直接在实际项目中使用。

* 如果您确定直接使用本程序,使用之前请仔细确认相关安全设置。

*

*/

require_once 'JSON.php';

$php_path = dirname(__FILE__) . '/';

$php_url = dirname($_SERVER['PHP_SELF']) . '/';

//文件保存目录路径

$save_path = $php_path . '../../res/upload/';

//文件保存目录URL

$save_url = $php_url . '../../res/upload/';

//定义允许上传的文件扩展名

$ext_arr = array('image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),'flash' => array('swf', 'flv'),'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2', 'gif', 'jpg', 'jpeg', 'png', 'bmp'),

);

//最大文件大小

$max_size = 1000000;

$save_path = realpath($save_path) . '/';

//有上传文件时

if (empty($_FILES) === false) {

//原文件名

$file_name = $_FILES['imgFile']['name'];

//服务器上临时文件名

$tmp_name = $_FILES['imgFile']['tmp_name'];

// alert("请选择文件。" . $tmp_name);

//文件大小

$file_size = $_FILES['imgFile']['size'];

//检查文件名

if (!$file_name) {

alert("请选择文件。");

}

$dir_name = empty($_GET['dir']) ? 'image' : trim($_GET['dir']);

//获得文件扩展名

$temp_arr = explode(".", $file_name);

$file_ext = array_pop($temp_arr);

$file_ext = trim($file_ext);

$file_ext = strtolower($file_ext);

//检查扩展名

if (in_array($file_ext, $ext_arr[$dir_name]) === false) {

alert("上传文件扩展名是不允许的扩展名。/n只允许" . implode(",", $ext_arr[$dir_name]) . "格式。");

}

//新文件名

$new_file_name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;

//移动文件

$s = new SaeStorage();

$result = $s->upload('article', $new_file_name, $tmp_name);

if(!$result) {

alert("上传文件失败。");

}

// @chmod($file_path, 0644);

$file_url = $result;

//$s->getUrl( 'redstones' , $new_file_name );

header('Content-type: text/html; charset=UTF-8');

$json = new Services_JSON();

echo $json->encode(array('error' => 0, 'url' => $file_url));

exit;

}

function alert($msg) {

header('Content-type: text/html; charset=UTF-8');

$json = new Services_JSON();

echo $json->encode(array('error' => 1, 'message' => $msg));

exit;

}

?> 本文链接http://www.cxybl.com/html/wlbc/Php/20130601/38186.html

欢迎大家阅读《sae storage:在PHP中使用Sina Sae提供的_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码

e7ce419cf2d6ad34d01da2ceb8829eed.png

微信 赏一包辣条吧~

023a57327877fb4402bcc76911ec18ea.png

支付宝 赏一听可乐吧~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值