From 0520b7e34033956ca35bdabc0d8a81c86439b6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=94=E5=93=A5?= Date: Tue, 25 Sep 2018 11:39:15 +0800 Subject: [PATCH] * Finish task#4795. --- module/file/control.php | 36 ++++++++++++++++++++++++++++++++++++ www/api.php | 8 ++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/module/file/control.php b/module/file/control.php index 9571a83a0b..7da85a885b 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -75,6 +75,42 @@ class file extends control } } + /** + * @access public + * @return void + */ + public function apiUpload($uid = '') + { + $file = $this->file->getUpload('file'); + $file = $file[0]; + if($file) + { + if($file['size'] == 0) die(json_encode(array('status' => 'error', 'message' => $this->lang->file->errorFileUpload))); + if(@move_uploaded_file($file['tmpname'], $this->file->savePath . $this->file->getSaveName($file['pathname']))) + { + /* Compress image for jpg and bmp. */ + $file = $this->file->compressImage($file); + + $file['addedBy'] = $this->app->user->account; + $file['addedDate'] = helper::today(); + unset($file['tmpname']); + $this->dao->insert(TABLE_FILE)->data($file)->exec(); + + $_SERVER['SCRIPT_NAME'] = 'index.php'; + $fileID = $this->dao->lastInsertID(); + $url = $this->createLink('file', 'read', "fileID=$fileID", $file['extension']); + if($uid) $_SESSION['album'][$uid][] = $fileID; + die(json_encode(array('status' => 'seccess', 'data' => commonModel::getSysURL() . $this->config->webRoot . $url))); + } + else + { + $error = strip_tags(sprintf($this->lang->file->errorCanNotWrite, $this->file->savePath, $this->file->savePath)); + die(json_encode(array('status' => 'error', 'message' => $error))); + } + } + die(json_encode(array('status' => 'error', 'message' => $this->lang->file->errorFileUpload))); + } + /** * AJAX: get upload request from the web editor. * diff --git a/www/api.php b/www/api.php index 47b3c0f838..565bf7aeb2 100644 --- a/www/api.php +++ b/www/api.php @@ -13,7 +13,7 @@ */ /* Set the error reporting. */ error_reporting(0); - +define('RUN_MODE', 'api'); /* Start output buffer. */ ob_start(); @@ -44,7 +44,11 @@ $common->checkPriv(); $app->loadModule(); $output = json_decode(ob_get_clean()); -$output = json_encode($output->data); +$data = new stdClass(); +$data->status = $output->status; +if(isset($output->message)) $data->message = $output->message; +if(isset($output->data)) $data->data = json_decode($output->data); +$output = json_encode($data); unset($_SESSION['ENTRY_CODE']); unset($_SESSION['VALID_ENTRY']);