Skip to content

Instantly share code, notes, and snippets.

@eonarik
Last active March 12, 2018 15:25
Show Gist options
  • Save eonarik/539514badd98d7860e3c3cfa68e9b645 to your computer and use it in GitHub Desktop.
Save eonarik/539514badd98d7860e3c3cfa68e9b645 to your computer and use it in GitHub Desktop.
modx snippet fileInfo
<?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