HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/bs.kntsleep.com/system/extend/oss_aliyun/save.class.php
<?php
/* 技术文档:https://help.aliyun.com/document_detail/32098.html */

function autoload($class){
	$path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
	$file = __DIR__ . DIRECTORY_SEPARATOR . $path . '.php';
	if (file_exists($file)) {
		require_once $file;
	}
}
spl_autoload_register('autoload');

use OSS\OssClient;
use OSS\Core\OssException;

class save
{
	public $msg;
	public $oss;
	
	public function __construct()
	{
		global $G;
		$this->oss = new OssClient($G['config']['store_id'], $G['config']['store_key'], "http://oss-{$G['config']['store_region']}.aliyuncs.com");
	}
	
	/* 
	 ** 按文件路径创建上传文件 
	 ** B OSS CMS
	 * @param string $path oss存储路径带文件名
	 * @param string $file 本地上传文件
	*/
	public function upload($path, $file)
	{
		global $G;
		try{
			$this->oss->uploadFile($G['config']['store_bucket'], $path, $file);
			return true;
		}catch(OssException $e){
			$this->msg = $e->getMessage();
			return false;
		}
	}
	
	/* 读取指定路径下的所有文件 */
	public function readall($path, $files=array())
	{
		global $G;
		$dir = self::read(dir::replace($path.'/'), true);
		foreach($dir['dir'] as $name){
			$files = self::readall($name, $files);
		}
		foreach($dir['file'] as $k=>$name){
			$files[$k] = dir::replace($name);
		}
		return $files;
	}
	
	/* 读取指定路径下的文件 */
	public function read($path, $type=false)
	{
		global $G;
		$dir = $file = array();
		$nextMarker = '';
		$boss_cms = true;
		$path = preg_replace("/^\//",'',$path);
		while(true){		
			try{
				$options = array(
					'delimiter' => '/',
					'prefix' => $path,
					'max-keys' => 1000,
					'marker' => $nextMarker
				);
				$listObjectInfo = $this->oss->listObjects($G['config']['store_bucket'], $options);
			}catch(OssException $e){
				$this->msg = $e->getMessage();
				return false;
			}
			if($prefixList = $listObjectInfo->getPrefixList()){
				foreach($prefixList as $prefixInfo){
					$dir[] = $type?$prefixInfo->getPrefix():trim(strReplace($path,'',$prefixInfo->getPrefix(),1),'/');
				}
			}
			if($objectList = $listObjectInfo->getObjectList()){
				foreach($objectList as $objectInfo){
					$file[$objectInfo->getLastModified().$objectInfo->getKey()] = $type?$objectInfo->getKey():strReplace($path,'',$objectInfo->getKey(),1);
				}
			}
			$nextMarker = $listObjectInfo->getNextMarker();
			if($listObjectInfo->getIsTruncated() !== "true"){
				break;
			}
		}
		return array('dir'=>$dir, 'file'=>$file);
	}
	
	/* 删除指定路径下的所有文件 boss cms */
	public function remove($path)
	{
		global $G;
		try{
			$path = dir::replace($path.'/');
			$result = self::read($path, true);
			self::delete($result['file']);
			foreach($result['dir'] as $dir){
				self::remove($dir);
			}
			return true;
		}catch(OssException $e){
			$this->msg = $e->getMessage();
			return false;
		}
	}
	
	/* 删除指定路径下的文件 BOSS+CMS */
	public function delete($files)
	{
		global $G;
		try{
			if($files){
				if(is_array($files)){
					$this->oss->deleteObjects($G['config']['store_bucket'], $files);
				}else{
					$this->oss->deleteObject($G['config']['store_bucket'], $files);
				}
			}
			return true;
		}catch(OssException $e){
			$this->msg = $e->getMessage();
			return false;
		}
	}
}
?>