Библиотека для cis, online, cms1
This commit is contained in:
commit
3c2e614d87
269 changed files with 39854 additions and 0 deletions
82
core/file.php
Normal file
82
core/file.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
require_once 'core/sort.php';
|
||||
|
||||
//Ñòàíîâèòüñÿ ïîõîæå íà ðàáîòó ôàéëîâ ÷åðåç SPL âîçìîæíî ñòîèò ðåàëèçîâàòü íà áàçå åãî
|
||||
class FileRecord
|
||||
{
|
||||
public $file;
|
||||
protected $src;
|
||||
protected $parent;
|
||||
|
||||
function __construct(array $file, $src, $parent = false)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->filename = $src;
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
function get($name) {
|
||||
return isset($this->file[$name]) ? $this->file[$name] : null;
|
||||
}
|
||||
|
||||
function fileStat()
|
||||
{
|
||||
$type = is_dir($this->filename);
|
||||
return array(
|
||||
'name' => ($this->parent) ? ".." : $this->getName(),
|
||||
'type' => $type,
|
||||
'extension' => ($type) ? 'folder' : pathinfo($this->filename, PATHINFO_EXTENSION),
|
||||
'date' => date("d.m.Y H:i", $this->getTime()),
|
||||
'access' => 0,
|
||||
'size' => ($type) ? "" : $this->getSizeString(),
|
||||
'state' => isset($this->file['state']) ? $this->file['state'] : 'unknown',
|
||||
'title' => $this->getTitle(),
|
||||
/*'author' => $this->file['author'],
|
||||
'description' => $this->file['description'],
|
||||
'keywords' => $this->file['keywords'],*/
|
||||
);
|
||||
}
|
||||
|
||||
function isExpected()
|
||||
{
|
||||
if (isset($this->file['state'])) {
|
||||
return ($this->file['state'] == 'expected');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getSizeString()
|
||||
{
|
||||
$size = $this->getSize();
|
||||
foreach (array('á ', 'Ká', 'Má') as $suffix) {
|
||||
if (($size / 1024) <= 1) {
|
||||
return round($size, 0) . ' ' . $suffix;
|
||||
}
|
||||
$size /= 1024;
|
||||
}
|
||||
return round($size, 0) . ' GB';
|
||||
}
|
||||
|
||||
function getSize()
|
||||
{
|
||||
return ($this->isExpected()) ? 0 : filesize($this->filename);
|
||||
}
|
||||
|
||||
function getTime()
|
||||
{
|
||||
return ($this->isExpected()) ? 0 : filemtime($this->filename);
|
||||
}
|
||||
|
||||
function getName()
|
||||
{
|
||||
return pathinfo($this->filename, PATHINFO_BASENAME);
|
||||
}
|
||||
|
||||
function getTitle()
|
||||
{
|
||||
return isset($this->file['title']) ? $this->file['title'] : $this->getName();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue