path_info

The path_info function parses a file path and returns its components. 

The values returned can include:

  • basename - the filename including the extension
  • dirname - the path up to the filename
  • extension - the file extension - this is the only value that may be missing if the file path doesn't contain a file extension
  • filename - the file name minus the extension

If only a specific file path part is required then that can be passed as the second parameter. If it exists in the file path then it will be returned. Otherwise false will be returned.

Example

{% set path = '/path/to/file/myfile.pdf' %}
{% set fileParts = path_info('/path/to/myfile.pdf) %}
{# The above example will return #}
array (
    'basename' => 'myfile.pdf',
    'dirname' => '/path/to',
    'extension' => 'pdf'
    'filename' => 'myfile'
)

Arguments

The path_info function has the following signature.

path_info(path, part)

Arguments Description
path

The file path value to parse.

part

The single file path part to return. If the part exists in the file path then it will be returned. Otherwise false is returned. Typically that would only happen with "extension".

If the part exists in the URL then the value returned is a string.

Valid part values are:

  • basename
  • dirname
  • extension
  • filename

< Back to the list of functions