public function beforeSave() { $this->updatedAt = time(); if ($this->type == 'data') { //Auto update title if finance data $this->title = \Eva\EvaEngine\Text\Substring::substrCn(strip_tags($this->getContentHtml()), 100); } //Data importance will overwrite news importance if ($data = $this->getData()) { $this->importance = $data->importance; } if ($this->getDI()->getRequest()->hasFiles()) { $upload = new UploadModel(); $files = $this->getDI()->getRequest()->getUploadedFiles(); if (!$files) { return; } $file = $files[0]; $file = $upload->upload($file); if ($file) { $this->imageId = $file->id; $this->image = $file->getLocalUrl(); } } }
public function beforeSave() { if ($this->getDI()->getRequest()->hasFiles()) { $upload = new UploadModel(); $files = $this->getDI()->getRequest()->getUploadedFiles(); if (!$files) { return; } $file = $files[0]; $file = $upload->upload($file); if ($file) { $this->imageId = $file->id; $this->image = $file->getLocalUrl(); } } }
public function beforeSave() { if ($this->password) { $this->password = self::passwordHash($this->password); } if ($this->getDI()->getRequest()->hasFiles()) { $upload = new UploadModel(); $files = $this->getDI()->getRequest()->getUploadedFiles(); if (!$files) { return; } $file = $files[0]; $file = $upload->upload($file); if ($file) { $this->avatarId = $file->id; $this->avatar = $file->getFullUrl(); } } }
/** * @operationName("Upload Media") * @operationDescription("Upload Media") */ public function indexAction() { if (!$this->request->isPost() || !$this->request->hasFiles()) { $this->response->setStatusCode('400', 'No Upload Files'); return $this->response->setJsonContent(array('errors' => array(array('code' => 400, 'message' => 'ERR_FILE_NO_UPLOAD')))); } $upload = new Models\Upload(); $fileinfo = array(); try { $files = $this->request->getUploadedFiles(); //Only allow upload the first file by force $file = $files[0]; $file = $upload->upload($file); if ($file) { $fileinfo = $file->toArray(); $fileinfo['localUrl'] = $file->getLocalUrl(); } } catch (\Exception $e) { return $this->showExceptionAsJson($e, $upload->getMessages()); } return $this->response->setJsonContent($fileinfo); }
public function updateCategory() { if ($this->getDI()->getRequest()->hasFiles()) { $upload = new UploadModel(); $files = $this->getDI()->getRequest()->getUploadedFiles(); if (!$files) { return; } $file = $files[0]; $file = $upload->upload($file); if ($file) { $this->imageId = $file->id; $this->image = $file->getFullUrl(); } } $this->save(); }
/** * * @SWG\Api( * path="/admin/media", * description="Media related api", * produces="['application/json']", * @SWG\Operations( * @SWG\Operation( * method="POST", * summary="Create new media", * notes="Returns a media based on ID", * @SWG\Parameters( * @SWG\Parameter( * name="upload", * description="Media info", * paramType="body", * required=true, * type="file" * ) * ) * ) * ) * ) * @operationName("上传文件") * @operationDescription("上传文件") */ public function postAction() { if (!$this->request->isPost() || !$this->request->hasFiles()) { throw new Exception\InvalidArgumentException('No data input'); } $upload = new Models\Upload(); try { $files = $this->request->getUploadedFiles(); //Only allow upload the first file by force $file = $files[0]; $file = $upload->upload($file); if ($file) { $data = $file->dump(Models\FileManager::$defaultDump); return $this->response->setJsonContent($data); } } catch (\Exception $e) { return $this->showExceptionAsJson($e, $upload->getMessages()); } }
/** * @param array $data */ public function updateCategory(array $data) { if ($this->getDI()->getRequest()->hasFiles()) { $upload = new UploadModel(); $files = $this->getDI()->getRequest()->getUploadedFiles(); if (!$files) { return; } $file = $files[0]; $file = $upload->upload($file); if ($file) { $this->imageId = $file->id; $this->image = $file->getFullUrl(); } } $pinyin = new Pinyin(); $this->initial = substr($pinyin->transformUcwords($this->categoryName), 0, 1); if ($this->save()) { $parents = isset($data['parents']) ? $data['parents'] : array(); $cateCate = new CategoryCategory(); $cateCate->forFullUpdateCategoryByParentId($this->id, $parents); } }