arne-groskurth / temp-file
TempFile is a small library inspired by the SplTempFileObject providing solutions for commonly occurring tasks when dealing with temporary files.
Installs: 30 459
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 3
Open Issues: 0
Requires
- php: ^5.4 || ^7.0 || ^8.0
- ext-fileinfo: *
- symfony/http-foundation: ^3.1 || ^4.0 || ^5.0
Requires (Dev)
- phpunit/phpunit: ^5.5 || ^9.3.0
- roave/security-advisories: dev-latest
README
TempFile is a small library inspired by the SplTempFileObject providing solutions for commonly occurring tasks when dealing with temporary files.
Setup
$ composer require arne-groskurth/temp-file
Usage
<?php use ArneGroskurth\TempFile\TempFile; $tempFile = new TempFile(); // TempFile offers all commonly used file-related functions including fread, fwrite, ftell, fseek and feof. $tempFile->fwrite('Hello World!'); // Construct response object and write to stdout // (Requires installation of package "symfony/http-foundation") $tempFile->send(); // Obtain path-based access to temporary file within callback function $tempFile->accessPath(function($path) { $content = file_get_contents($path); $content = str_replace('Hello World!', 'Got you!', $content); file_put_contents($path, $content); }); // Echos 'Got yout!' print $tempFile->getContent(); // Persist temporary file to some path $tempFile->persist('/my/path/filename.ext');