File modules/cms/action/file/FileEditAction.class.php
Last commit: Wed Mar 9 13:28:52 2022 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()'
1 <?php 2 namespace cms\action\file; 3 use cms\action\FileAction; 4 use cms\action\Method; 5 use language\Messages; 6 use util\exception\ValidationException; 7 use util\Upload; 8 9 10 class FileEditAction extends FileAction implements Method { 11 public function view() { 12 // MIME-Types aus Datei lesen 13 $this->setTemplateVars( $this->file->getProperties() ); 14 } 15 public function post() { 16 $upload = new Upload(); 17 18 if ( $upload->isAvailable() ) 19 { 20 // File received as attachement. 21 try 22 { 23 $upload->processUpload(); 24 } 25 catch( \Exception $e ) 26 { 27 throw $e; 28 } 29 30 $this->file->filename = $upload->filename; 31 $this->file->extension = $upload->extension; 32 $this->file->size = $upload->size; 33 $this->file->save(); 34 35 $this->file->value = $upload->value; 36 $this->file->saveValue(); 37 } 38 elseif( $value = $this->request->getText('value') ) 39 { 40 // File value received 41 $this->file->value = $value; 42 43 if ( strtolower($this->request->getText('encoding')) == 'base64') 44 // file value is base64-encoded 45 $this->file->value = base64_decode($this->file->value); 46 47 $this->file->saveValue(); 48 } 49 else 50 { 51 // No file received. 52 throw new ValidationException('value'); 53 } 54 55 $this->file->setTimestamp(); 56 57 $this->addNoticeFor( $this->file, Messages::VALUE_SAVED ); 58 } 59 }
Downloadmodules/cms/action/file/FileEditAction.class.php
History Wed, 9 Mar 2022 13:28:52 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()' Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Thu, 19 Nov 2020 14:49:58 +0100 Jan Dankert Fix: Action::addNotice() is replaced by Action::addNoticeFor() Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.