<?php
|
|
|
|
/**
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
class Filemanager
|
|
{
|
|
/**
|
|
*
|
|
*
|
|
* @param [type] $path [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function find($path)
|
|
{
|
|
$results = [];
|
|
|
|
// getting files from directory
|
|
$files = scandir($path);
|
|
|
|
foreach($files as $file) {
|
|
|
|
// ignore parent directories
|
|
if ($file === '.' || $file === '..') {
|
|
continue;
|
|
}
|
|
|
|
// getting meta for file
|
|
$meta = stat($path.'/'.$file);
|
|
|
|
$result = [
|
|
'filename' => $file,
|
|
'is_file' => is_file($path.'/'.$file),
|
|
'meta' => [
|
|
'updated_at' => \Carbon\Carbon::parse($meta['mtime'])->format('d.m.Y h:m:i')
|
|
]
|
|
];
|
|
|
|
if ($result['is_file']) {
|
|
$result['size'] = $this->formatBytes($meta['size']);
|
|
}
|
|
|
|
$results[] = $result;
|
|
}
|
|
|
|
return $results;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param [type] $size [description]
|
|
* @param integer $precision [description]
|
|
* @return [type] [description]
|
|
*/
|
|
private function formatBytes($size, $precision = 1)
|
|
{
|
|
if ($size === 0) {
|
|
return '0 bytes';
|
|
}
|
|
|
|
$base = log($size, 1024);
|
|
$suffixes = array('bytes', 'kB', 'MB', 'G', 'T');
|
|
|
|
return round(pow(1024, $base - floor($base)), $precision).' '.$suffixes[floor($base)];
|
|
}
|
|
|
|
}
|