flavioheleno/interim

An open_basedir aware wrapper for tmpfile() and sys_get_temp_dir()

v0.1.0 2023-03-27 18:38 UTC

This package is auto-updated.

Last update: 2024-10-27 22:13:26 UTC


README

Interim is a simple wrapper around PHP's tmpfile() and sys_get_temp_dir() that takes into account open basedir restriction.

Installation

To use Interim, simple run:

composer require flavioheleno/interim

Usage

When open_basedir is disabled, Interim behaves exactly the same way as sys_get_temp_dir():

// before
var_dump(sys_get_temp_dir());
// string(4) "/tmp"

// after
var_dump(Interim\Temporary::getDirectory());
// string(4) "/tmp"

// -or-
var_dump(Interim\Temporary::getDirectory('tmp'));
// string(4) "/tmp"

// -or-
var_dump(Interim\Temporary::getDirectory('/var/tmp'));
// string(4) "/tmp"

When open_basedir is enabled, Interim will check if temporary dir is in the open_basedir list, if not, it will return an alternative.

ini_set('open_basedir', '/var/www/html:/var/tmp');

// before (if you try to use "/tmp", an "open_basedir restriction in effect" warning will be raised)
var_dump(sys_get_temp_dir());
// string(4) "/tmp"

// after
var_dump(Interim\Temporary::getDirectory());
// string(4) "/var/www/html"

// -or-
var_dump(Interim\Temporary::getDirectory('tmp'));
// string(4) "/var/www/html/tmp"

// -or-
var_dump(Interim\Temporary::getDirectory('/var/tmp'));
// string(4) "/var/tmp"

License

This library is licensed under the MIT License.