Initial commit

This commit is contained in:
易焱
2021-04-18 18:51:51 +08:00
commit ec705f2fa8
3240 changed files with 623103 additions and 0 deletions
@@ -0,0 +1,80 @@
<?php
/**
* 本地文件处理类
* @author Nintendov
*/
namespace Vin\FileStorage\Driver;
use Vin\FileStorage;
class File extends FileStorage{
/**
* 本地写文件
*/
public function put($rootpath,$filename, $content,$maxSize=-1, $cover = TRUE){
$filename = '.'.$rootpath.$filename;
if($maxSize!=-1){
if(strlen($content>$maxSize)){
return '文件大小超过限制';
}
}
$dir = dirname($filename);
if(!is_dir($dir))
mkdir($dir,0755,true);
if(false === file_put_contents($filename,$content)){
E(L('_STORAGE_WRITE_ERROR_').':'.$filename);
}else{
$this->contents[$filename]=$content;
return true;
}
}
/**
* 遍历获取目录下的指定类型的文件
* @param $path
* @param array $files
* @return array
*/
public function listFile($rootpath, $path ,$allowFiles='all'){
$path = $_SERVER['DOCUMENT_ROOT'].__ROOT__.$rootpath.$path;
return $this->getList($path, $allowFiles);
}
public function getList($path ,$allowFiles='all' , &$files = array()){
if (!is_dir($path)) return null;
if(substr($path, strlen($path) - 1) != '/') $path .= '/';
$handle = opendir($path);
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
$path2 = $path . $file;
if (is_dir($path2)) {
$this->getList($path2, $allowFiles, $files);
} else {
if($allowFiles!='all'){
if (preg_match("/\.(".$allowFiles.")$/i", $file)) {
$files[] = array(
'url'=> substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])),
'mtime'=> filemtime($path2)
);
}
}else{
$files[] = array(
'url'=> substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])),
'mtime'=> filemtime($path2)
);
}
}
}
}
return $files;
}
/**
* 得到路径
*/
public function getPath($rootpath,$path){
$path = __ROOT__.$rootpath.$path;
return $path;
}
}
@@ -0,0 +1,100 @@
<?php
/**
*
* @author Nintendov
*/
namespace Vin\FileStorage\Driver;
use Vin\FileStorage;
class Sae extends FileStorage{
private $st;
private $error;
public function __construct(){
if(!function_exists('memcache_init')){
header('Content-Type:text/html;charset=utf-8');
exit('请在SAE平台上运行代码。');
}
$this->st = new \SaeStorage();
}
public function getFilename($filename){
if(strpos($filename, __ROOT__)) $filename = str_replace(__ROOT__, '', $filename,1);
return $filename;
}
/**
* 写文件
* @param 文件名
* @param 文件内容
* @param 限制尺寸 默认不限制
* @param 是否覆盖 默认是
*/
public function put($rootpath,$filename, $content,$maxSize=-1, $cover = TRUE){
$rootpath = trim($rootpath,'/');
$filename = $this->getFilename($filename);
if($maxSize!=-1) if(strlen($content)>$maxSize) return '文件大小超过限制';
if($cover){
if($this->st->fileExists($rootpath,$filename)) $this->st->delete($rootpath,$filename);
}
return $this->st->write($rootpath,$filename,$content);
}
public function listFile($rootpath,$path , $allowFiles='all'){
$rootpath = trim($rootpath,'/');
$path = trim($path,'/');
return $this->getList($rootpath, $path,$allowFiles);
}
/**
* 遍历获取目录下的指定类型的文件
* @param $path
* @param array $files
* @return array
*/
public function getList($domain, $path, $allowFiles='all' , &$list=array()){
$allowFiles = 'all';
$handle = $this->st->getListByPath($domain , $path , 1000);
if($handle['dirNum'] > 0){
foreach ($handle['dirs'] as $dir) {
$dirname = trim($dir['fullName'],'/');
$this->getList($domain, $dirname,$allowFiles, $list);
}
}
foreach ($handle['files'] as $file){
if($allowFiles!='all'){
if (preg_match("/\.(".$allowFiles.")$/i", $file['fullName'])) {
$list[] = array(
'url'=> $this->st->getUrl($domain,$file['fullName']),
'mtime'=> $file['uploadTime']
);
}
}else{
$list[] = array(
'url'=> $this->st->getUrl($domain,$file['fullName']),
'mtime'=> $file['uploadTime']
);
}
}
return $list;
}
/**
* 得到路径
*/
public function getPath($rootpath,$path){
$rootpath = trim($rootpath,'/');
$url = $this->st->getUrl($rootpath,$path);
return $url;
}
}