Oihana PHP

touchFile.php

Table of Contents

Functions

touchFile()  : string
Creates a file if it does not exist, or updates its modification and access times.

Functions

touchFile()

Creates a file if it does not exist, or updates its modification and access times.

touchFile(string $file[, int|null $mtime = null ][, int|null $atime = null ][, bool $createDirectory = true ]) : string

Thin, exception-throwing wrapper around touch(). When $mtime is null, the current time is used. When $mtime is given but $atime is null, the access time is set to $mtime as well. The parent directory is created on demand.

Parameters
$file : string

Path to the file to touch.

$mtime : int|null = null

Modification timestamp (default: null → current time).

$atime : int|null = null

Access timestamp (default: null → same as $mtime).

$createDirectory : bool = true

Whether to create the parent directory if missing (default: true).

Tags
throws
FileException

If the file cannot be touched.

DirectoryException

If the parent directory is missing and cannot be created.

author

Marc Alcaraz (ekameleon)

since
1.2.0
example
use function oihana\files\touchFile;

touchFile( '/var/run/app.lock' ) ;                 // create or bump to now
touchFile( '/data/marker' , strtotime('-1 day') ) ; // backdate the mtime
Return values
string

The file path.

On this page

Search results