* Finish task#4795.
This commit is contained in:
@@ -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
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user