alikdex/tmpfile

Alternative work with temporary files in php

1.0 2020-01-02 10:13 UTC

This package is auto-updated.

Last update: 2024-04-14 04:49:35 UTC


README

Alternative work with temporary files in php

Install

composer require alikdex/tmpfile

Usage

<?php

require 'vendor/autoload.php';

// Create file
$tmpfile = new \TA\TmpFile;

// Create with options: __construct($content, $suffix, $prefix, $directory)
$tmpfile = new \TA\TmpFile('Hello, world!', '.txt', 'foo_', '/path/to/your/tmp');

// Gets fullpath
(string) $tmpfile;
//or
$tmpfile->getPathname();

// Write data
$tmpfile->write('foo');

// Write with flags. Eg. lock file.
$tmpfile->write('bar', LOCK_EX);

// Append to end of file.
$tmpfile->append('baz');

// Gets content
$tmpfile->read();

// Read a piece of content: read($offset, $length);
$tmpfile->read(7, 5);

// Delete file manually (by default, this applied when object destruct)
$tmpfile->delete();

// Keed after usage (don't delete)
$tmpfile->autoDelete = false;