PHP code example of alikdex / tmpfile

1. Go to this page and download the library: Download alikdex/tmpfile library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alikdex / tmpfile example snippets




eate 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;