|
@@ -30,6 +30,10 @@ class Core
|
|
|
protected $size;
|
|
|
|
|
|
protected $base = '';
|
|
|
+
|
|
|
+ protected $base64 = false;
|
|
|
+
|
|
|
+ protected $yun = false;
|
|
|
|
|
|
/**
|
|
|
* __construct
|
|
@@ -147,7 +151,7 @@ class Core
|
|
|
*/
|
|
|
private function check_size()
|
|
|
{
|
|
|
- if ($this->config['width'] > 0 || $this->config['height'] > 0) {
|
|
|
+ if (!$this->limit) {
|
|
|
$this->limit = getimagesize($this->data['file']['tmp_name']);
|
|
|
}
|
|
|
|
|
@@ -178,38 +182,82 @@ class Core
|
|
|
$this->output['status'] = 1;
|
|
|
|
|
|
if (is_string($this->data['file'])) {
|
|
|
- /*
|
|
|
- if (strpos($this->data['file'], 'http') !== false) {
|
|
|
- $this->output['status'] = -1;
|
|
|
- $this->output['message'] = '暂时不支持复制网络文件';
|
|
|
- return $this->output;
|
|
|
+ if (strstr($this->data['file'], 'base64,') && isset($this->data['pic'])) {
|
|
|
+ $temp = explode('base64,', $this->data['file']);
|
|
|
+ $type = str_replace(array('data:', ';'), '', $temp[0]);
|
|
|
+ $file = str_replace(' ', '+', $temp[1]);
|
|
|
+ $file = str_replace('=', '', $temp[1]);
|
|
|
+ $file = base64_decode($file);
|
|
|
+ $name = $this->data['local'] = Dever::local($this->data['pic']);
|
|
|
+ $size = strlen($file);
|
|
|
+ $size = ($size - ($size/8)*2)/1024;
|
|
|
+ $this->base64 = true;
|
|
|
+ } else {
|
|
|
+ $name = urldecode($this->data['file']);
|
|
|
}
|
|
|
- */
|
|
|
- $this->root();
|
|
|
|
|
|
- header('Content-type: text/json; charset=utf-8');
|
|
|
-
|
|
|
- $path = Dever::path($this->base, 'tmp/');
|
|
|
- $name = urldecode($this->data['file']);
|
|
|
$this->data['file'] = array();
|
|
|
- $this->data['file']['name'] = 'Tmp' . sha1($name);
|
|
|
- //$this->data['file']['name'] = 'Tmp' . Helper::rand(8) . md5(microtime() . rand(0,1000)) . '.jpg';
|
|
|
- $this->data['file']['tmp_name'] = $path . $this->data['file']['name'];
|
|
|
-
|
|
|
- if (!is_file($this->data['file']['tmp_name'])) {
|
|
|
- if (strstr($name, 'tp=webp')) {
|
|
|
- $name = str_replace('tp=webp', 'tp=jpeg', $name);
|
|
|
- } elseif (strstr($name, '.webp')) {
|
|
|
- $name = str_replace('.webp', '.jpg', $name);
|
|
|
+ if (!$this->yun && strstr($name, 'http')) {
|
|
|
+ $this->base64 = false;
|
|
|
+ $this->root();
|
|
|
+ header('Content-type: text/json; charset=utf-8');
|
|
|
+ $path = Dever::path($this->base, 'tmp/');
|
|
|
+
|
|
|
+ $this->data['file']['name'] = 'Tmp' . sha1($name);
|
|
|
+ $this->data['file']['tmp_name'] = $path . $this->data['file']['name'];
|
|
|
+
|
|
|
+ if (!is_file($this->data['file']['tmp_name'])) {
|
|
|
+ if (strstr($name, 'tp=webp')) {
|
|
|
+ $name = str_replace('tp=webp', 'tp=jpeg', $name);
|
|
|
+ } elseif (strstr($name, '.webp')) {
|
|
|
+ $name = str_replace('.webp', '.jpg', $name);
|
|
|
+ }
|
|
|
+ if (!isset($file)) {
|
|
|
+ $file = Dever::curl($name);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (stristr($file, 'webp')) {
|
|
|
+ # 将webp图片转成jpg
|
|
|
+ $this->ext = '.jpg';
|
|
|
+ }
|
|
|
+ file_put_contents($this->data['file']['tmp_name'], $file);
|
|
|
+ $this->data['file']['size'] = filesize($this->data['file']['tmp_name']);
|
|
|
}
|
|
|
- $file = Dever::curl($name);
|
|
|
- if (stristr($file, 'webp')) {
|
|
|
- # 将webp图片转成jpg
|
|
|
+ } else {
|
|
|
+ $this->data['file']['name'] = $name;
|
|
|
+ $this->data['file']['tmp_name'] = $file;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($type)) {
|
|
|
+ $this->data['file']['type'] = $type;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($size)) {
|
|
|
+ $this->data['file']['size'] = $size;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($this->data['param'])) {
|
|
|
+ $this->limit = array($this->data['param']['param_w'], $this->data['param']['param_h']);
|
|
|
+ if (isset($this->data['name'])) {
|
|
|
+ $param = implode('_', array_values($this->data['param']));
|
|
|
+ $this->data['file']['name'] = '.' . $this->data['name'] . $param;
|
|
|
+ if ($this->base64) {
|
|
|
+ $this->data['name'] = $this->data['file']['name'];
|
|
|
+ } else {
|
|
|
+ $filename = md5($this->data['pic']) . '.' . pathinfo($this->data['pic'], PATHINFO_EXTENSION);
|
|
|
+ $file = $this->base . $this->data['key'] . $this->path . $filename;
|
|
|
+ if (!is_file($file)) {
|
|
|
+ $content = Dever::curl($name);
|
|
|
+ $this->path();
|
|
|
+ file_put_contents($file, $content);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->data['name'] = $filename . $this->data['file']['name'];
|
|
|
+ }
|
|
|
+
|
|
|
$this->ext = '.jpg';
|
|
|
}
|
|
|
- file_put_contents($this->data['file']['tmp_name'], $file);
|
|
|
}
|
|
|
- $this->data['file']['size'] = filesize($this->data['file']['tmp_name']);
|
|
|
|
|
|
} else {
|
|
|
header("Content-type: application/json; charset=utf-8");
|
|
@@ -262,6 +310,10 @@ class Core
|
|
|
$param['set_key'] = md5($this->output['url']);
|
|
|
$param['set_ext'] = $this->ext;
|
|
|
|
|
|
+ if (isset($this->data['cate'])) {
|
|
|
+ $param['set_cate'] = $this->data['cate'];
|
|
|
+ }
|
|
|
+
|
|
|
if ($this->limit) {
|
|
|
$param['set_width'] = $this->limit[0];
|
|
|
$param['set_height'] = $this->limit[1];
|
|
@@ -284,6 +336,9 @@ class Core
|
|
|
$param['add_key'] = md5($this->output['url']);
|
|
|
$param['add_ext'] = $this->ext;
|
|
|
$param['add_upload'] = $this->data['key'];
|
|
|
+ if (isset($this->data['cate'])) {
|
|
|
+ $param['add_cate'] = $this->data['cate'];
|
|
|
+ }
|
|
|
|
|
|
if ($this->limit) {
|
|
|
$param['add_width'] = $this->limit[0];
|
|
@@ -302,6 +357,46 @@ class Core
|
|
|
Dever::load('upload/file-insert', $param);
|
|
|
}
|
|
|
|
|
|
+ private function img()
|
|
|
+ {
|
|
|
+ $this->img = isset($this->img) ? $this->img : new Img();
|
|
|
+ $this->img->setType('im');
|
|
|
+
|
|
|
+ return $this->img;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getName()
|
|
|
+ {
|
|
|
+ $this->path()->name($this->data['file']['name'])->ext()->file();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function path()
|
|
|
+ {
|
|
|
+ $date = explode('-', date("Y-m-d"));
|
|
|
+
|
|
|
+ $this->path = $this->config['id'] . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function name($name)
|
|
|
+ {
|
|
|
+ if (isset($this->data['name'])) {
|
|
|
+ $this->name = $this->data['name'];
|
|
|
+ } else {
|
|
|
+ $this->name = md5($name);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function ext()
|
|
|
+ {
|
|
|
+ $this->ext = $this->ext ? $this->ext : '.' . pathinfo($this->data['file']['name'], PATHINFO_EXTENSION);
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* getExt
|
|
|
*
|