arne-groskurth/temp-file

此包已被弃用,不再维护。未建议替代包。

TempFile 是一个受 SplTempFileObject 启发的小型库,为处理临时文件时遇到的常见任务提供解决方案。

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 是一个受 SplTempFileObject 启发的库,为处理临时文件时遇到的常见任务提供解决方案。

安装

$ composer require arne-groskurth/temp-file

使用

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