https://github.com/gocom/eien
PHP library for managing temporary files
https://github.com/gocom/eien
Last synced: 11 months ago
JSON representation
PHP library for managing temporary files
- Host: GitHub
- URL: https://github.com/gocom/eien
- Owner: gocom
- License: mit
- Created: 2013-05-19T15:05:23.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-12-12T15:26:13.000Z (over 12 years ago)
- Last Synced: 2025-03-21T15:43:00.623Z (about 1 year ago)
- Language: PHP
- Size: 348 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Eien - PHP, have a temporary file
====
[Packagist](https://packagist.org/packages/rah/eien) | [Twitter](http://twitter.com/gocom) | [Issues](https://github.com/gocom/eien/issues) | [](https://travis-ci.org/gocom/eien)
Eien is a small PHP helper library for handling temporary files. Get, create, make, remove and flush temporary files and directories. Currently unstable, work in progress.
Basic usage
----
### Get a path to an available temporary file
```php
echo (string) new Rah_Eien_Temporary_File();
```
### Create a temporary file and move it to its final location once done
The file is moved to location specified with the optional Rah_Eien_File::$final option, if defined. The moving is performed once there are no other references to the instance, script is closed or when the move() method is called.
```php
$tmp = new Rah_Eien_File();
$tmp->final('/path/to/final/location.txt');
$file = new Rah_Eien_Temporary_File($tmp);
```
If you want moving to happen automatically, the easiest ways are extending, which allows you to perform your actions within it, unsetting the instance once you are done with it or wrapping the instance to its own contexts, like an anonymous function.
### Make a temporary file from an existing file
In addition to creating brand new temporary files, or getting paths as strings, you can also create temporary file instances from other files. The specified files are copied to your temporary directory, and you get an instance point to the new temporary instance.
```php
$tmp = new Rah_Eien_File();
$tmp->file('/path/to/source/file.txt');
echo (string) new Rah_Eien_Temporary_File($tmp);
```
### Create a new temporary directory and return its path
```php
echo (string) new Rah_Eien_Temporary_Directory();
```