File modules/cms/action/folder/FolderCreatefileAction.class.php
Last commit: Wed Oct 14 01:46:43 2026 +0200 Jan Dankert PHP 8: Fix: Method signature must match the interface.
1 <?php 2 namespace cms\action\folder; 3 use cms\action\FolderAction; 4 use cms\action\Method; 5 use cms\model\BaseObject; 6 use cms\model\File; 7 use cms\model\Permission; 8 use language\Messages; 9 use util\exception\ValidationException; 10 use util\Http; 11 use util\Upload; 12 13 14 class FolderCreatefileAction extends FolderAction implements Method { 15 public function getRequiredPermission(): int 16 { 17 return Permission::ACL_CREATE_FILE; 18 } 19 20 public function view() { 21 // Maximale Dateigroesse. 22 $maxSizeBytes = $this->maxFileSize(); 23 $this->setTemplateVar('max_size' ,($maxSizeBytes/1024).' KB' ); 24 $this->setTemplateVar('maxlength',$maxSizeBytes ); 25 26 $this->setTemplateVar('objectid',$this->folder->objectid ); 27 } 28 29 30 public function post() { 31 $type = $this->request->getText('type' ); 32 $name = $this->request->getText('name' ); 33 $filename = $this->request->getText('filename' ); 34 $description = $this->request->getText('description'); 35 36 $file = new File(); 37 38 // Die neue Datei wird über eine URL geladen und dann im CMS gespeichert. 39 if ( $url = $this->request->getText('url') ) 40 { 41 $http = new Http(); 42 $http->setUrl( $url ); 43 44 $ok = $http->request(); 45 46 if ( !$ok ) 47 { 48 $this->addWarningFor( $this->folder,Messages::COMMON_VALIDATION_ERROR,[],$http->error); 49 throw new ValidationException( 'url' ); 50 } 51 52 $file->filename = BaseObject::urlify( $name ); 53 $file->size = strlen($http->body); 54 $file->value = $http->body; 55 $file->parentid = $this->folder->objectid; 56 $file->projectid = $this->folder->projectid; 57 } 58 elseif ( $value = $this->request->getText('value') ) 59 { 60 // New file is inserted. 61 $file->filename = BaseObject::urlify( $filename ); 62 $file->value = $value; 63 $file->size = strlen($file->value); 64 $file->parentid = $this->folder->objectid; 65 $file->projectid = $this->folder->projectid; 66 } 67 else 68 { 69 // File was uploaded. 70 $upload = new Upload('file'); 71 72 try 73 { 74 $upload->processUpload(); 75 } 76 catch( \Exception $e ) 77 { 78 // technical error. 79 throw new \RuntimeException('Exception while processing the upload: '.$e->getMessage(), 0, $e); 80 81 //throw new \ValidationException( $upload->parameterName ); 82 } 83 84 $file->filename = BaseObject::urlify( $upload->filename ); 85 $file->extension = $upload->extension; 86 $file->size = $upload->size; 87 $file->parentid = $this->folder->objectid; 88 $file->projectid = $this->folder->projectid; 89 90 $file->value = $upload->value; 91 } 92 93 $file->persist(); // Datei hinzufuegen 94 $file->setNameForAllLanguages( $name,$description ); 95 96 $this->addNoticeFor( $file, Messages::ADDED ); 97 $this->setTemplateVar('objectid',$file->objectid); 98 99 $this->folder->setTimestamp(); 100 } 101 }
Downloadmodules/cms/action/folder/FolderCreatefileAction.class.php
History Wed, 14 Oct 2026 01:46:43 +0200 Jan Dankert PHP 8: Fix: Method signature must match the interface. 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()' Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Sun, 14 Mar 2021 23:51:49 +0100 Jan Dankert Refactoring: Using the ValidationException where possible. Sat, 6 Mar 2021 03:42:38 +0100 Jan Dankert New: Better permission checks. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Wed, 18 Nov 2020 01:46:36 +0100 Jan Dankert Refactoring of model classes: New method persist() and some other cleanups. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.