Oihana PHP

makePrivateTemporaryDirectory.php

Table of Contents

Functions

makePrivateTemporaryDirectory()  : string
Creates a working directory that only its owner can read: mode `0700`.

Functions

makePrivateTemporaryDirectory()

Creates a working directory that only its owner can read: mode `0700`.

makePrivateTemporaryDirectory(string|array<string|int, string> $path[, string|null $base = null ]) : string

Meant for the work that must not be seen by the other accounts of the machine while it is in progress — a database dump, a configuration file with its credentials, the decrypted content of an encrypted archive. With the usual 0755, all of it is readable by every local user for as long as it sits there.

The mode is applied again after the creation, because a directory left behind by an earlier run keeps the permissions it was created with, and the umask may have narrowed them anyway.

An empty $path is refused. makeTemporaryDirectory() given null or '' returns the system temporary directory itself — it asks for a path, not a prefix — and a caller that deletes what it was handed when the work is done would then delete the whole of /tmp.

Parameters
$path : string|array<string|int, string>

The sub-path inside the base, as one string or as segments. Empty segments are dropped.

$base : string|null = null

The directory to create it in: the system temporary directory when null, or another volume when the work is too large for it.

Tags
throws
DirectoryException

When the path is empty, or the directory cannot be created.

example
use function oihana\files\makePrivateTemporaryDirectory;
use function oihana\files\deleteDirectory;

$work = makePrivateTemporaryDirectory( [ 'backup' , 'example.com' ] ) ;
// /tmp/backup/example.com, mode 0700

$work = makePrivateTemporaryDirectory( 'backup' , '/srv/work' ) ;
// /srv/work/backup, mode 0700

makePrivateTemporaryDirectory( '' ) ; // throws

deleteDirectory( $work ) ;
author

Marc Alcaraz (ekameleon)

since
1.7.0
Return values
string —

The path of the directory.

On this page

Search results