dd / evolutioncms-snippets-ddgetfileinfo
Displays information about a file: type, mime, size in readable format, path, name, extension, etc.
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:modxevo-snippet
pkg:composer/dd/evolutioncms-snippets-ddgetfileinfo
Requires
- php: >=7.4.0
- dd/evolutioncms-libraries-ddtools: >=0.60.0
This package is auto-updated.
Last update: 2025-10-17 11:04:57 UTC
README
Displays information about a file: type, mime, size in readable format, path, name, extension, etc.
Requires
- PHP >= 7.4
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.60
Installation
Using (MODX)EvolutionCMS.libraries.ddInstaller
Just run the following PHP code in your sources or Console:
// Include (MODX)EvolutionCMS.libraries.ddInstaller require_once( $modx->getConfig('base_path') . 'assets/libs/ddInstaller/require.php' ); // Install (MODX)EvolutionCMS.snippets.ddGetFileInfo \DDInstaller::install([ 'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetFileInfo', ]);
- If
ddGetFileInfois not exist on your site,ddInstallerwill just install it. - If
ddGetFileInfois already exist on your site,ddInstallerwill check it version and update it if needed.
Manually
1. Elements → Snippets: Create a new snippet with the following data
- Snippet name:
ddGetFileInfo. - Description:
<b>2.5.1</b> Displays information about a file: type, mime, size in readable format, path, name, extension, etc.. - Category:
Core. - Parse DocBlock:
no. - Snippet code (php): Insert content of the
ddGetFileInfo_snippet.phpfile from the archive.
2. Elements → Manage Files
- Create a new folder
assets/snippets/ddGetFileInfo/. - Extract the archive to the folder (except
ddGetFileInfo_snippet.php).
Parameters description
-
file- Description: File name (path).
- Valid values:
stringFilePath— the path to the file can be specified relative to the site root (/at the beginning does not matter, both variants are supported), or the full path (including$modx->config['base_path'])stringUrl— you can specify not only a local file, but also an Internet address, but in this case not all functions are supported for objective reasons
- Required
-
file_docField- Description: A document field (including TV) containing the path to the file (if you want the snippet to get the file address from the document field).
- Valid values:
string - Default value: —
-
file_docId- Description: Resource ID, from the field of which you want to get the file address.
- Valid values:
integerDocId - Default value: —
-
sizeUnitFormat- Description: Format of file size unit.
- Values are case insensitive (the following names are equal:
'enshort','EnShort','ENSHORT', etc).
- Values are case insensitive (the following names are equal:
- Valid values:
'none''EnShort'— e. g.MB'EnFull'— e. g.Megabyte'RuShort'— e. g.Мб'RuFull'— e. g.Мегабайт
- Default value:
'EnShort'
- Description: Format of file size unit.
-
sizePrecision- Description: The number of decimal digits to round to.
- Valid values:
integer - Default value:
2
-
output- Description: File information to output (if
tplis not set). - Valid values:
'size''extension''type''typeMime''name''path'
- Default value:
'size'
- Description: File information to output (if
-
tpl- Description: Output template (if the parameter is absent, file data corresponding to
outputwill be returned).- Available placeholders:
[+file+]— full file address[+name+]— file name[+path+]— file path[+size+]— file size with a unit in a human-readable format[+extension+]— file extension[+type+]— file type:'archive''image''video''audio''text''pdf''word''excel''powerpoint'
[+typeMime+]— content type in MIME format (only for local files, not for URLs)
- Available placeholders:
- Valid values:
stringChunkNamestring— use inline templates starting with@CODE:
- Default value: —
- Description: Output template (if the parameter is absent, file data corresponding to
-
tpl_placeholders- Description: Additional data has to be passed into the
tpl.- Nested objects and arrays are supported too:
{"someOne": "1", "someTwo": "test" }=>[+someOne+], [+someTwo+].{"some": {"a": "one", "b": "two"} }=>[+some.a+],[+some.b+].{"some": ["one", "two"] }=>[+some.0+],[+some.1+].
- Nested objects and arrays are supported too:
- Valid values:
stringJsonObject— as JSONstringHjsonObject— as HJSONstringQueryFormatted— as Query string- It can also be set as a native PHP object or array (e. g. for calls through
$modx->runSnippet):arrayAssociativeobject
- Default value: —
- Description: Additional data has to be passed into the
Examples
Run the snippet through \DDTools\Snippet::runSnippet without DB and eval
// Include (MODX)EvolutionCMS.libraries.ddTools require_once( $modx->getConfig('base_path') . 'assets/libs/ddTools/modx.ddtools.class.php' ); // Run (MODX)EvolutionCMS.snippets.ddGetFileInfo \DDTools\Snippet::runSnippet([ 'name' => 'ddGetFileInfo', 'params' => [ 'file' => 'assets/images/evo-logo.png', 'output' => 'size', ], ]);