|
@@ -15,7 +15,7 @@ class Save
|
|
|
8 => 'exe,msi',
|
|
|
);
|
|
|
private $type = 1;
|
|
|
- private function init($id)
|
|
|
+ public function init($id)
|
|
|
{
|
|
|
$this->config = Dever::db('rule', 'upload')->find($id);
|
|
|
if (!$this->config) {
|
|
@@ -25,6 +25,37 @@ class Save
|
|
|
if (!$this->config['save']) {
|
|
|
Dever::error('存储位置错误');
|
|
|
}
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function get($id)
|
|
|
+ {
|
|
|
+ $this->init($id);
|
|
|
+ $result = array();
|
|
|
+ $result['id'] = $id;
|
|
|
+ $result['chunkSize'] = $this->config['chunk'];
|
|
|
+ $result['path'] = $id;
|
|
|
+ $result['size'] = $this->config['size'];
|
|
|
+ $result['accept'] = '';
|
|
|
+ $result['mine'] = array();
|
|
|
+ $mine = $this->getExtByMine(false, true);
|
|
|
+ $type = explode(',', $this->config['type']);
|
|
|
+ foreach ($type as $v) {
|
|
|
+ if (isset($this->ext[$v])) {
|
|
|
+ $result['accept'] .= '.' . str_replace(',', ',.', $this->ext[$v]);
|
|
|
+ $temp = explode(',', $this->ext[$v]);
|
|
|
+ foreach ($temp as $v2) {
|
|
|
+ if (isset($mine[$v2])) {
|
|
|
+ $result['mine'][] = $mine[$v2];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result['type'] = $this->config['save']['type'];
|
|
|
+ if ($result['type'] > 1) {
|
|
|
+ $result += Dever::load('tool', 'upload')->get($this->config['save'])->getInfo();
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
public function act($id, $source, $default_ext = '', $uid = false)
|
|
@@ -45,6 +76,7 @@ class Save
|
|
|
}
|
|
|
$total = Dever::input('chunks');
|
|
|
if ($total > 1) {
|
|
|
+ $chunk['size'] = $this->config['chunk'];
|
|
|
$chunk['uid'] = Dever::input('uid');
|
|
|
$chunk['timestamp'] = Dever::input('timestamp');
|
|
|
$chunk['cur'] = Dever::input('chunk');
|
|
@@ -121,25 +153,45 @@ class Save
|
|
|
$dest = $this->config['id'] . '/' . $this->getDest($name, $ext, $uid);
|
|
|
# type 1是文件复制 2是base64 3是远程文件复制
|
|
|
$url = Dever::load('tool', 'upload')->get($this->config['save'])->upload($type, $source, $dest, $chunk, $this);
|
|
|
+ $data = $this->up($source_name, $name, $dest, $this->config['size'], $this->config['width'] ?? 0, $this->config['height'] ?? 0);
|
|
|
+ $data['url'] = $url;
|
|
|
+ $data['type'] = $this->type;
|
|
|
+ if (isset($content)) {
|
|
|
+ @unlink($source);
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addFile($url, $source_name, $name, $dest, $size)
|
|
|
+ {
|
|
|
+ if ($this->config['save']['type'] > 1) {
|
|
|
+ $url = Dever::load('tool', 'upload')->get($this->config['save'])->getUrl(3, $url, $this);
|
|
|
+ if (isset($this->config['size']) && $this->config['size']) {
|
|
|
+ $size = $this->config['size'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->up($source_name, $name, $dest, $size, $this->config['width'] ?? 0, $this->config['height'] ?? 0);
|
|
|
+ $data['url'] = $url;
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function up($source_name, $name, $dest, $size, $width = 0, $height = 0)
|
|
|
+ {
|
|
|
$file['rule_id'] = $this->config['id'];
|
|
|
$file['name'] = $name;
|
|
|
$data = $file;
|
|
|
$data['source_name'] = $source_name;
|
|
|
$data['file'] = $dest;
|
|
|
$data['save_id'] = $this->config['save_id'];
|
|
|
- $data['size'] = $this->config['size'];
|
|
|
- if (isset($this->config['width'])) {
|
|
|
- $data['width'] = $this->config['width'];
|
|
|
+ $data['size'] = $size;
|
|
|
+ if ($width) {
|
|
|
+ $data['width'] = $width;
|
|
|
}
|
|
|
- if (isset($this->config['height'])) {
|
|
|
- $data['height'] = $this->config['height'];
|
|
|
+ if ($height) {
|
|
|
+ $data['height'] = $height;
|
|
|
}
|
|
|
$data['id'] = Dever::db('file', 'upload')->up($file, $data);
|
|
|
- $data['url'] = $url;
|
|
|
- $data['type'] = $this->type;
|
|
|
- if (isset($content)) {
|
|
|
- @unlink($source);
|
|
|
- }
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
@@ -258,9 +310,8 @@ class Save
|
|
|
return $dest;
|
|
|
}
|
|
|
|
|
|
- protected function getExtByMine($mine)
|
|
|
+ protected function getExtByMine($mine, $flip = false, $result = false)
|
|
|
{
|
|
|
- $mine = trim($mine);
|
|
|
$config = array
|
|
|
(
|
|
|
'application/envoy' => 'evy',
|
|
@@ -415,6 +466,13 @@ class Save
|
|
|
'image/webp' => 'webp',
|
|
|
);
|
|
|
|
|
|
+ if ($flip) {
|
|
|
+ $config = array_flip($config);
|
|
|
+ }
|
|
|
+ if (!$mine) {
|
|
|
+ return $config;
|
|
|
+ }
|
|
|
+ $mine = trim($mine);
|
|
|
if (isset($config[$mine])) {
|
|
|
return $config[$mine];
|
|
|
} else {
|