GWcode FileInfo

ExpressionEngine plugin to get information about files on your server, such as the file's extension, size, the filename without the extension, file type, the dimensions (if the file is an image), etc.

I've created this plugin when we needed to output the base name (filename but without the extension) of each image in a Matrix gallery, and the filesize. When the project was finished, I decided to expand the features and realease it as a free plugin.

The plugin provides two tags, one to get information about a single file and one to get information about all files in a directory. Let's break it down to show what parameters and variables are available for both tags.

{exp:gwcode_fileinfo:single}

Get information about a single file.

Parameters

Parameter

Possible Value(s)

Example

Description

file

a path or URL to a file on your server

file="my_file.jpg"

The single file you'd like to get information for.

variable_prefix

anything

variable_prefix="gw:"

Allows you to add a prefix to all variables used by GWcode FileInfo, to prevent conflicts with another add-on or native ExpressionEngine variables when you nest tags. For example, {file_name} will become {gw:file_name}.

Variables

Variable

This will output..

{file_fullpath}

The full server path to the file. Example: /full/server/path/to/docroot/media/my_image.jpg

The number of bits for each color. Example: 8. Click here for more information.

{image_channels}

Will be 3 for RGB and 4 for CMYK pictures.

{image_mime}

The MIME type of the image. This can be different from {file_extension_mime} when for example image.jpg has been renamed to image.gif. This variable will then output image/jpeg, whereas {file_extension_mime} will output image/gif.

{exp:gwcode_fileinfo:multiple}

Get information about files in a directory.

Parameters

Parameter

Possible Value(s)

Example

Description

directory

a path or URL to a directory on your server

directory="/path/to/directory"

The directory that contains the files you'd like to get information for.

variable_prefix

anything

variable_prefix="gw:"

Allows you to add a prefix to all variables used by GWcode FileInfo, to prevent conflicts with another add-on or native ExpressionEngine variables when you nest tags. For example, {file_name} will become {gw:file_name}.

Variables

Besides all variables from the {exp:gwcode_fileinfo:single} tag above, the following additional variables are available for the {exp:gwcode_fileinfo:multiple} tag.

Variable

Description

{count}

Incrementing number for each file in the output.

{total_results}

Total number of files being returned in the output.

{switch}

This variable permits you to rotate through any number of values, which you can use to add CSS classes for example. Example: {switch="one|two|three"}