
详细介绍
七牛云对象存储
1.注意客户购买的空间的存储区域,区域不同对应的上传域名不同 如下表:
destoon 七牛云上传文件 用下面源码替换include/ftp.class.php,
<?php
/*
[DESTOON B2B System] Copyright (c) 2008-2018 www.destoon.com
This is NOT a freeware, use is subject to license.txt
*/
defined('IN_DESTOON') or exit('Access Denied');
class dftp {
var $connected = 0;
var $ak;
var $sk;
var $bk;
function __construct($ftphost, $ftpuser, $ftppass, $ftpport = 21, $root = '/', $pasv = 0, $ssl = 0) {
$this->connected = 1;
$this->ak = $ftpuser;
$this->sk = $ftppass;
$this->bk = $root;
}
function dftp($ftphost, $ftpuser, $ftppass, $ftpport = 21, $root = '/', $pasv = 0, $ssl = 0) {
$this->__construct($ftphost, $ftpuser, $ftppass, $ftpport, $root, $pasv, $ssl);
}
function dftp_delete($file) {
$key = $file;
$entry = $this->bk.':'.$key;
$encodedEntryURI = $this->dftp_encode($entry);
$signingStr = "/delete/".$encodedEntryURI."\n";
$sign = hash_hmac('sha1', $signingStr, $this->sk, true);
$encodedSign = $this->dftp_encode($sign);
$accessToken = $this->ak.':'.$encodedSign;
$headers = array();
$headers[] = 'Authorization: QBox '.$accessToken;
$cur = curl_init('http://rs.qiniu.com/delete/'.$encodedEntryURI);
curl_setopt($cur, CURLOPT_POST, 1);
curl_setopt($cur, CURLOPT_POSTFIELDS, '');
curl_setopt($cur, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($cur, CURLOPT_HEADER, 0);
curl_setopt($cur, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cur, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cur, CURLOPT_HTTPHEADER, $headers);
$rec = curl_exec($cur);
curl_close($cur);
}
function dftp_put($local, $remote = '') {
global $DT_TIME;
$remote or $remote = $local;
$local = DT_ROOT.'/'.$local;
$key = $remote;
$P = array();
$P['scope'] = $this->bk.':'.$key;
$P['deadline'] = $DT_TIME + 3600;
$putPolicy = json_encode($P);
$encodedPutPolicy = $this->dftp_encode($putPolicy);
$sign = hash_hmac('sha1', $encodedPutPolicy, $this->sk, true);
$encodedSign = $this->dftp_encode($sign);
$uploadToken = $this->ak.':'.$encodedSign.':'.$encodedPutPolicy;
$headers = array();
$headers[] = 'Expect: ';
$par = array();
$par['key'] = $key;
$par['token'] = $uploadToken;
$par['file'] = '@'.$local;
$cur = curl_init('http://upload.qiniu.com/');
curl_setopt($cur, CURLOPT_POST, 1);
curl_setopt($cur, CURLOPT_POSTFIELDS, $par);
curl_setopt($cur, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($cur, CURLOPT_HEADER, 0);
curl_setopt($cur, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cur, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cur, CURLOPT_HTTPHEADER, $headers);
$rec = curl_exec($cur);
curl_close($cur);
if(strpos($rec, 'key') !== false) {
$arr = json_decode($rec, true);
if($arr['key'] == $key) return true;
}
return false;
}
function dftp_chdir() {
if(!function_exists('hash_hmac')) return false;
if(!function_exists('curl_init')) return false;
return true;
}
function dftp_encode($str) {
return str_replace(array('+', '/'), array('-', '_'), base64_encode($str));
}
}
?>
后台
FTP主机:upload.qiniu.com FTP帐号:AccessKey 例如:db2N1b4xpqtA7UltwE97feeetgssYNjHFf9k-ZFs FTP密码:SecretKey 例如:E_1yje34kU6Zq-EVsqgxducdfcdc6nZiLshMpL_O 远程存储目录:存储空间 bucket 名称 例如:img-destoon-com 远程访问URL:绑定域名 例如:http://img.destoon.com/