makeTimestampedFile.php
Table of Contents
Functions
- makeTimestampedFile() : string|null
- Generates a timestamped file path if not exist. Using a formatted date and optional prefix/suffix.
Functions
makeTimestampedFile()
Generates a timestamped file path if not exist. Using a formatted date and optional prefix/suffix.
makeTimestampedFile([string|null $date = null ][, string $basePath = Char::EMPTY ][, string|null $extension = null ][, string $prefix = Char::EMPTY ][, string $suffix = Char::EMPTY ][, string|null $timezone = 'Europe/Paris' ][, string|null $format = 'Y-m-dTH:i:s' ][, bool $mustExist = false ]) : string|null
Combines a date/time string (or the current time) with optional prefix, suffix, and base path to generate a unique file name. The file is not created on disk.
Parameters
- $date : string|null = null
-
Optional date/time string to use. If null or invalid, the current date/time is used ("now").
- $basePath : string = Char::EMPTY
-
Optional base path in which to place the file. Defaults to the current directory.
- $extension : string|null = null
-
Optional extension to append to the file name (e.g., ".log", ".txt").
- $prefix : string = Char::EMPTY
-
Optional string to prepend to the file name.
- $suffix : string = Char::EMPTY
-
Optional string to append to the file name (e.g., "2025-12-01T14:00:00-hello"").
- $timezone : string|null = 'Europe/Paris'
-
Timezone identifier (e.g., 'Europe/Paris'). Defaults to 'Europe/Paris'.
- $format : string|null = 'Y-m-dTH:i:s'
-
Date format compatible with DateTime::format(). Defaults to 'Y-m-d\TH:i:s'.
- $mustExist : bool = false
-
Whether the generated file must exist. If true, asserts the file exists. Defaults to false.
Tags
Return values
string|null —The full path of the generated file, or null on failure.