<?php namespace Phpcmf\Library;
class Storage {
public $ci;
protected $object;
private function _init($attachment) {
if ($attachment['type']) {
switch ($attachment['type']) {
case 1:
$this->object = new \Phpcmf\ThirdParty\Storage\Ftp();
break;
case 2:
$this->object = new \Phpcmf\ThirdParty\Storage\Oss();
break;
case 3:
$this->object = new \Phpcmf\ThirdParty\Storage\Qcloud();
break;
case 4:
$this->object = new \Phpcmf\ThirdParty\Storage\Baidu();
break;
case 5:
$this->object = new \Phpcmf\ThirdParty\Storage\Qiniu();
break;
default:
$path = FCPATH.'ThirdParty/Storage/';
$local = dr_dir_map($path, 1);
foreach ($local as $dir) {
if (is_file($path.$dir.'/App.php')) {
$cfg = require $path.$dir.'/App.php';
if ($cfg['id'] && $cfg['id'] == $attachment['type']) {
$newClassName2 = '\\Phpcmf\\ThirdParty\\Storage\\'.ucfirst($dir);
$this->object = new $newClassName2;
}
}
}
if (!$this->object) {
exit(dr_array2string(dr_return_data(0, '云存储类型['.$attachment['type'].']对应的程序不存在')));
}
break;
}
} else {
$this->object = new \Phpcmf\ThirdParty\Storage\Local();
}
}
public function upload($type, $data, $file_path, $attachment, $watermarkk) {
$this->_init($attachment);
return $this->object->init($attachment, $file_path)->upload($type, $data, $watermarkk);
}
public function delete($attachment, $filename) {
$this->_init($attachment);
return $this->object->init($attachment, $filename)->delete();
}
}