info()

public function info(string $file_path): array

Description

Retrieves metadata about a file, including its size, last modification time, permissions, and MIME type.

Parameters

ParameterTypeDescription
$file_path string The path to the file.

Return Value Details

The method returns an associative array containing the following keys:

KeyTypeDescription
file_name string The filename without the directory path (e.g., "document.pdf").
size int File size in bytes.
human_readable_size string Formatted file size (e.g., "2.45 MB").
modified_time int Last modification time as a Unix timestamp.
permissions int Raw file permissions as an integer.
readable_permissions string Formatted permissions in octal notation (e.g., "0644").
mime_type string The MIME type of the file (e.g., "application/pdf").

Exception Handling: This method throws an exception if the file does not exist. Always verify the file exists using $this->file->exists($file_path) before calling info().

Example #1

The code sample below demonstrates how to display detailed file information on a document management page.

In the view file, you can display the file information:

Example #2

The example above shows how to use file information to implement a storage quota system.

Example #3

The example above demonstrates how to filter and display files by type using MIME information.

Working with Timestamps: The modified_time value is returned as a Unix timestamp (number of seconds since January 1, 1970). Use PHP's date() function to convert it to a human-readable format: date('F j, Y g:i A', $file_info['modified_time']) produces output like "December 26, 2024 3:45 PM".