{fileinfo:url:info}

Description

Returns one piece of metadata about a file, given its URL. The url is usually a file or upload field getter; the second argument names what you want. type and name are read from the URL string alone, so they work anywhere. size, bytesize, link, typesize, crc, time, mime and ifwebimg need the real file to be readable on disk or over HTTP and return empty when it is not. With no second argument, or an empty url, the result is empty. The companion command filelink builds a full download link and calls fileinfo internally for the type and size.

Parameters

url required default (empty string)

The file URL to inspect, normally a field getter like _#FILE____ (a file/upload field). A leading-slash path is resolved against the current host. An empty url yields an empty result.

info optional default (empty string)

Which piece of metadata to return. One of the allowed values below. If omitted the result is empty (there is no implicit default). type and name are derived from the URL string alone; the size, link, typesize, crc, time, mime and ifwebimg values need the real file to be readable on disk or over HTTP and return empty when it is not.

Examples

virtual[{fileinfo:_#FILE____:link}]
Expectedreport.pdf [pdf - 157 kB] (HTML)
Actual[_  [TXT - ]]
link builds a ready-made download anchor (the same as filelink) with the filename, plus the type and size appended. Its output is HTML markup, so it is illustrative rather than a plain-text test.
test[{fileinfo::type}]
Expected[]
Actual[]
An empty URL yields an empty result regardless of the requested info. This is the safe outcome when a file field is unset.
test[{fileinfo:https://example.org/files/report.pdf:type}]
Expected[pdf]
Actual[pdf]
The type value is the file extension taken from the URL, in lowercase. In real templates the first argument is usually a file-field getter such as _#FILE____ instead of a literal URL.
test[{fileinfo:https://example.org/a/b/report.final.pdf:name}]
Expected[report.final.pdf]
Actual[report.final.pdf]
The name value is the bare filename (basename) from the URL path. Inner dots are kept; only the directory part is removed.
virtual[{fileinfo:_#FILE____:size}]
Expected[157 kB] (depends on the actual file)
Actual[]
size needs the real file, read from disk (uploads) or fetched over HTTP. It prints kB up to 1 MB and MB above. Use bytesize for the raw integer. Empty when the file cannot be read - so this is a runtime-dependent value, shown here illustratively.
virtual[{fileinfo:_#FILE____:mime}]
Expected[image/jpeg] (depends on the actual file)
Actual[]
mime sniffs the content type from the file on local disk (e.g. image/jpeg, application/pdf). Returns empty if the file is not present locally. Runtime-dependent.
test[{fileinfo:https://example.org/files/photo.JPG?v=3:name}]
Expected[photo.JPG]
Actual[photo.JPG]
Only the path portion of the URL is used, so any ?query is dropped. The original letter case of the name is preserved.
test[{fileinfo:https://example.org/files/report.pdf}]
Expected[]
Actual[]
Without a second argument there is no implicit default, so the result is empty. Always name the info you want (type, name, size, ...).
virtual[{fileinfo:_#FILE____:ifwebimg}]
Expected[https://example.org/files/photo.jpg] (empty when not a web image)
Actual[]
ifwebimg returns the URL unchanged when the file is a browser-displayable image (jpeg, png, gif, webp, avif, svg, bmp), otherwise empty. Handy to guard an _<_img src_=_..._>_ tag. Needs the file on local disk.
virtual[{fileinfo:_#FILE____:typesize}]
Expected[pdf - 157 kB] (HTML badge)
Actual [TXT - ]]
typesize combines type and size into a small HTML badge like [pdf - 157 kB]. The size half is empty when the file cannot be read; the output is HTML, hence illustrative.
test[{fileinfo:https://example.org/files/README:type}]
Expected[TXT]
Actual[TXT]
When the filename has no extension, type falls back to the literal TXT.
virtual{filelink:_#FILE____:_#TEXT____:Download#: }
ExpectedDownload: Annual report [pdf - 157 kB] (HTML)
ActualDownload: _#TEXT____  [TXT - ]
The everyday pattern: a download link whose title and trailing badge come from fileinfo. filelink calls fileinfo internally for the type and size, so you rarely call typesize or link directly. Replace _#FILE____ and _#TEXT____ with your slice's file and label fields.