File modules/cms/action/file/FileUploadAction.class.php
Last commit: Mon Dec 6 01:38:41 2021 +0100 dankert Fixed the file/image upload.
1 <?php 2 3 namespace cms\action\file; 4 5 use cms\action\FileAction; 6 use cms\action\Method; 7 use cms\model\BaseObject; 8 use cms\model\Permission; 9 use language\Messages; 10 use util\Upload; 11 12 13 class FileUploadAction extends FileAction implements Method { 14 15 public function getRequiredPermission() { 16 return Permission::ACL_WRITE; 17 } 18 19 20 public function view() { 21 } 22 23 24 public function post() { 25 26 // File was uploaded. 27 $upload = new Upload('file'); 28 29 try 30 { 31 $upload->processUpload(); 32 } 33 catch( \Exception $e ) 34 { 35 // technical error. 36 throw new \RuntimeException('Exception while processing the upload: '.$e->getMessage(), 0, $e); 37 } 38 39 $this->file->filename = $upload->filename; 40 $this->file->extension = $upload->extension; 41 $this->file->size = $upload->size; 42 $this->file->persist(); 43 44 $this->file->value = $upload->value; 45 $this->file->saveValue(); 46 47 $this->addNoticeFor( $this->file, Messages::SAVED ); 48 } 49 }
Downloadmodules/cms/action/file/FileUploadAction.class.php
History Mon, 6 Dec 2021 01:38:41 +0100 dankert Fixed the file/image upload. Sat, 6 Mar 2021 03:42:38 +0100 Jan Dankert New: Better permission checks. Thu, 4 Mar 2021 23:47:18 +0100 Jan Dankert New method 'upload' for replacing file contents.