I have TV with input type "File". How can i use output of this file few times: 1. in one place as url 2. in one place as name of this file 3. in one place as size of this file
Thank you
1 - use your tv - <a href="[[++site_url]][[*myFileTv]]">My File</a>
2 - use snippet like this -
[[!getNameFromPath?&path=`[[*myFileTv]]`]]
and code of this snippen is -
<?php
$path = $modx->getOption('path', $scriptProperties, '');
$fileName = basename($path);
return $fileName;
3 - use another snippet -
[[!getSizeFromPath?&path=`[[*myFileTv]]`]]
which code is -
<?php
$path = $modx->getOption('path', $scriptProperties, '');
if (!empty($path)) {
$size = filesize(MODX_BASE_PATH . ltrim($path,'/'));
$sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
if ($size == 0) {
return('n/a');
} else {
return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]);
}
}