分享好友 教程首页 教程搜索 频道列表

DESTOON-七牛云对象存储

2019-08-26 21:0711021
+关注28
核心提示:destoon7.0系统七牛云对象存储1.注意客户购买的空间的存储区域,区域不同对应的上...

destoon7.0系统七牛云对象存储

1.注意客户购买的空间的存储区域,区域不同对应的上传域名不同


destoon  七牛云上传文件   用下面源码替换include/ftp.class.php

文件代码如下:

<?php
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;
		$par['file'] = file_get_contents($local);
		$cur = curl_init('http://upload-z2.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/


本文标签: #七牛云 #存储 #oss #附件分离
整理员:小黑
免责声明:凡注明来源本网的所有作品,均为本网合法拥有版权或有权使用的作品,欢迎转载,注明出处。非本网作品均来自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。
生成海报
相关评论1
您可能在找更多
下一篇
我来说两句
1