* Finish task#4795.

This commit is contained in:
滔哥
2018-09-25 11:39:15 +08:00
parent f32fa0e58c
commit 0520b7e340
2 changed files with 42 additions and 2 deletions
+36
View File
@@ -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.
*
+6 -2
View File
@@ -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']);