信呼v2.5.1版本
This commit is contained in:
88
include/chajian/aliossChajian.php
Normal file
88
include/chajian/aliossChajian.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* 阿里云oss服务
|
||||
*/
|
||||
class aliossChajian extends Chajian{
|
||||
|
||||
private $accesskeyid;
|
||||
private $accesskeysecret;
|
||||
|
||||
private $vendorbool=false;
|
||||
private $ossClient=false;
|
||||
|
||||
protected function initChajian()
|
||||
{
|
||||
$this->accesskeyid = getconfig('alioss_keyid');
|
||||
$this->accesskeysecret = getconfig('alioss_keysecret');
|
||||
$this->folder = getconfig('alioss_folder');
|
||||
$this->bucket = getconfig('alioss_bucket');
|
||||
|
||||
$path = ''.ROOT_PATH.'/include/vendor/autoload.php';
|
||||
if(file_exists($path) && $this->accesskeysecret){
|
||||
require_once($path);
|
||||
$this->vendorbool = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function isbool()
|
||||
{
|
||||
return $this->vendorbool;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function getOssClient()
|
||||
{
|
||||
if(!$this->ossClient){
|
||||
$fq = getconfig('alioss_region');
|
||||
$endpoint = 'http://oss-cn-'.$fq.'.aliyuncs.com';
|
||||
$this->ossClient = new \OSS\OssClient($this->accesskeyid, $this->accesskeysecret, $endpoint);
|
||||
}
|
||||
return $this->ossClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到oss
|
||||
*/
|
||||
public function uploadFile($path)
|
||||
{
|
||||
if(!$this->isbool())return returnerror('no install alioss');
|
||||
try{
|
||||
$ossClient = $this->getOssClient();
|
||||
$barr = $ossClient->uploadFile($this->bucket, $this->folder.'/'.$path, ROOT_PATH.'/'.$path);
|
||||
if(is_array($barr)){
|
||||
$info = $barr['info'];
|
||||
$carr = returnsuccess($barr);
|
||||
$carr['code']= 0;
|
||||
$carr['url'] = str_replace('http:','https:', $info['url']);
|
||||
$carr['filesize'] = $info['request_size'];
|
||||
return $carr;
|
||||
}else{
|
||||
return returnerror();
|
||||
}
|
||||
} catch(\OSS\Core\OssException $e) {
|
||||
return returnerror($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
public function download($path, $dstPath)
|
||||
{
|
||||
if(!$this->isbool())return returnerror('no install alioss');
|
||||
try{
|
||||
$ossClient = $this->getOssClient();
|
||||
$localfile = $dstPath;
|
||||
$options = array(
|
||||
\OSS\OssClient::OSS_FILE_DOWNLOAD => $localfile
|
||||
);
|
||||
$ossClient->getObject($this->bucket, $path, $options);
|
||||
$carr = returnsuccess($barr);
|
||||
$carr['code']= 0;
|
||||
return $carr;
|
||||
} catch(\OSS\Core\OssException $e) {
|
||||
return returnerror($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,9 @@ class inputChajian extends Chajian
|
||||
if($lens>0)$lenstr=' maxlength="'.$lens.'"';
|
||||
$onblue = ' onblur="c.inputblur(this, '.$iszb.')"';
|
||||
$iszhang= false;
|
||||
if($type=='text' && !isempt($data)){
|
||||
$attr.=' onkeyup="c.autocomplete(this,\''.$data.'\','.$a['id'].', '.$iszb.',event)" onclick="this.onkeyup()"';
|
||||
}
|
||||
$str = '<input class="inputs" type="text" value="'.$val.'" '.$attr.''.$onblue.''.$styles.''.$lenstr.' name="'.$fname.'">';
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user