arne-groskurth/temp-file

This package is abandoned and no longer maintained. No replacement package was suggested.

TempFile is a small library inspired by the SplTempFileObject providing solutions for commonly occurring tasks when dealing with temporary files.

1.5.0 2021-10-24 12:33 UTC

This package is auto-updated.

Last update: 2021-11-24 12:46:40 UTC


README

Build Status codecov License

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');