Last active
March 12, 2018 15:25
-
-
Save eonarik/539514badd98d7860e3c3cfa68e9b645 to your computer and use it in GitHub Desktop.
modx snippet fileInfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// v1.0.1 | |
$file = $modx->getOption('input', $scriptProperties, false); | |
$options = $modx->getOption('options', $scriptProperties, false); | |
if ($file) | |
{ | |
$full_path = MODX_BASE_PATH . '/' . ltrim($file, '/'); | |
list($key, $dop) = explode(':', $options); | |
switch ($key) | |
{ | |
case 'is_writable': | |
return is_writable($full_path); | |
case 'updatedon': | |
return filemtime($full_path); | |
case 'createdon': | |
return filectime($full_path); | |
case 'size': | |
$size = [ | |
'full' => filesize($full_path) | |
,'kb' => round(filesize($full_path) / 1024) . ' кб' | |
,'mb' => round(filesize($full_path) / (1024 * 1024), 2) . ' мб' | |
,'Gb' => round(filesize($full_path) / (1024 * 1024 * 1024), 2) . ' Гб' | |
]; | |
if ($dop) | |
{ | |
return $size[$dop]; | |
} | |
else | |
{ | |
if ($size['Gb'] < 1) | |
{ | |
if ($size['mb'] < 1) | |
{ | |
return $size['kb']; | |
} | |
else | |
{ | |
return $size['mb']; | |
} | |
} | |
else | |
{ | |
return $size['Gb']; | |
} | |
} | |
return $size['full']; | |
case 'ext': | |
$file = explode('.', $file); | |
return end($file); | |
case 'exists': | |
return file_exists($full_path); | |
default: | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment