file($this->FileName); //$FileInfo->close(); return($Result); } function GetSize($Item) { $FileName = $this->GetFullName($Item); if(file_exists($FileName)) $Result = filesize($FileName); else $Result = 0; return($Result); } function GetFullName() { $ParentId = $this->Directory; while($ParentId != null) { $DbResult = $this->Database->select('FileDirectory', '*', 'Id='.$ParentId); $DbRow = $DbResult->fetch_assoc(); $Path .= $DbRow['Name'].'/'; $ParentId = $DbRow['Parent']; } $Result = $this->UploadFileFolder.'/'.$Path.$File->Name; return($Result); } function GetExt() { return(substr($this->Name, 0, strpos($this->Name, '.') - 1)); } function Delete() { if(file_exists($this->GetFullName())) unlink($this->GetFullName()); } function GetContent() { if($this->TempName != '') $Content = file_get_contents($this->TempName); else $Content = file_get_contents($this->GetFullName()); return($Content); } } class TypeFile extends TypeBase { var $UploadFileFolder; var $FileDownloadURL; var $DirectoryId; function __construct($FormManager) { parent::__construct($FormManager); $this->FileDownloadURL = 'file'; $this->DirectoryId = null; } function OnView($Item) { $File = &$Item['Value']; return(''. $File.' ('.HumanSize($File->Size).')'); } function OnEdit($Item) { // Check max value of upload_max_filesize // ini_set("upload_max_filesize", "100M"); // $File = &$Item['Value']; $Output = ''; return($Output); } function OnLoad($Item) { if(!is_object($Item['Value'])) $Item['Value'] = new DbFile(); $File = &$Item['Value']; if(array_key_exists($Item['Name'], $_FILES) and ($_FILES[$Item['Name']]['name'] != '')) { $UploadFile = $_FILES[$Item['Name']]; if(file_exists($UploadFile['tmp_name'])) { $File->Name = $UploadFile['name']; $File->Size = $UploadFile['size']; $File->TempName = $UploadFile['tmp_name']; } } return($File); } function OnLoadDb($Item) { if(!is_object($Item['Value'])) $Item['Value'] = new DbFile(); $File = &$Item['Value']; $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id); if($DbResult->num_rows() > 0) { $DbRow = $DbResult->fetch_assoc(); $File->Name = $DbRow['Name']; $File->Size = $DbRow['Size']; $File->Directory = $DbRow['Directory']; } return($File); } function OnSaveDb($Item) { if(!is_object($Item['Value'])) $Item['Value'] = new DbFile(); $File = &$Item['Value']; $Properties = array('Name' => $File->Name, 'Size' => $File->GetSize(), 'Directory' => $File->Directory); $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id); if($DbResult->num_rows() > 0) { $DbRow = $DbResult->fetch_assoc(); if($File->TempName != '') { $FileName = $File->GetFullName(); unlink($FileName); } $this->Database->update('File', 'Id='.$File->Id, $Properties); } else { $this->Database->insert('File', $Properties); $File->Id = $this->Database->insert_id; } if(!move_uploaded_file($File->TempName, $FileName)) SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!'); } }