Changeset 887 for trunk/Common/Form/Types/File.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Form/Types/File.php
r874 r887 3 3 class DbFile 4 4 { 5 var$Id;6 var$FileName;7 var$Size;8 var$Directory;9 var$DirectoryId;10 var$TempName;5 public string $Id; 6 public string $FileName; 7 public int $Size; 8 public string $Directory; 9 public string $DirectoryId; 10 public string $TempName; 11 11 12 function DetectMimeType() 12 function DetectMimeType(): string 13 13 { 14 14 // For proper mime-type detection php-pecl-Fileinfo package should be installed on *nix systems … … 19 19 } 20 20 21 function GetSize($Item) 21 function GetSize($Item): int 22 22 { 23 23 $FileName = $this->GetFullName($Item); … … 27 27 } 28 28 29 function GetFullName() 29 function GetFullName(): string 30 30 { 31 $Path = ''; 31 32 $ParentId = $this->Directory; 32 33 while ($ParentId != null) … … 37 38 $ParentId = $DbRow['Parent']; 38 39 } 39 $Result = $this->UploadFileFolder.'/'.$Path.$ File->Name;40 $Result = $this->UploadFileFolder.'/'.$Path.$this->FileName; 40 41 return $Result; 41 42 } 42 43 43 function GetExt() 44 function GetExt(): string 44 45 { 45 46 return substr($this->Name, 0, strpos($this->Name, '.') - 1); 46 47 } 47 48 48 function Delete() 49 function Delete(): void 49 50 { 50 51 if (file_exists($this->GetFullName())) unlink($this->GetFullName()); 51 52 } 52 53 53 function GetContent() 54 function GetContent(): string 54 55 { 55 56 if ($this->TempName != '') $Content = file_get_contents($this->TempName); … … 61 62 class TypeFile extends TypeBase 62 63 { 63 var$UploadFileFolder;64 var$FileDownloadURL;65 var$DirectoryId;64 public string $UploadFileFolder; 65 public string $FileDownloadURL; 66 public string $DirectoryId; 66 67 67 function __construct( $FormManager)68 function __construct(FormManager $FormManager) 68 69 { 69 70 parent::__construct($FormManager); … … 72 73 } 73 74 74 function OnView( $Item)75 function OnView(array $Item): ?string 75 76 { 76 77 $File = &$Item['Value']; … … 79 80 } 80 81 81 function OnEdit( $Item)82 function OnEdit(array $Item): string 82 83 { 83 84 // Check max value of upload_max_filesize … … 89 90 } 90 91 91 function OnLoad( $Item)92 function OnLoad(array $Item): ?string 92 93 { 93 94 if (!is_object($Item['Value'])) $Item['Value'] = new DbFile(); … … 106 107 } 107 108 108 function OnLoadDb( $Item)109 function OnLoadDb(array $Item): ?string 109 110 { 110 111 if (!is_object($Item['Value'])) $Item['Value'] = new DbFile(); 111 112 $File = &$Item['Value']; 112 113 $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id); 113 if ($DbResult->num_rows ()> 0)114 if ($DbResult->num_rows > 0) 114 115 { 115 116 $DbRow = $DbResult->fetch_assoc(); … … 121 122 } 122 123 123 function OnSaveDb( $Item)124 function OnSaveDb(array $Item): ?string 124 125 { 125 126 if (!is_object($Item['Value'])) $Item['Value'] = new DbFile(); … … 128 129 'Size' => $File->GetSize(), 'Directory' => $File->Directory); 129 130 $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id); 130 if ($DbResult->num_rows ()> 0)131 if ($DbResult->num_rows > 0) 131 132 { 132 133 $DbRow = $DbResult->fetch_assoc(); … … 143 144 } 144 145 if (!move_uploaded_file($File->TempName, $FileName)) 145 SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!'); 146 $this->System->SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!'); 147 return ''; 146 148 } 147 149
Note:
See TracChangeset
for help on using the changeset viewer.