2017 © Pedro PelĂĄez
 

library php-tmpfile

A convenience class for temporary files

image

mikehaertl/php-tmpfile

A convenience class for temporary files

  • Monday, August 28, 2017
  • by mike
  • Repository
  • 1 Watchers
  • 30 Stars
  • 1,538,815 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 5 Versions
  • 10 % Grown

The README.md

php-tmpfile

GitHub Tests Packagist Version Packagist Downloads GitHub license, (*1)

A convenience class for temporary files., (*2)

Features

  • Create temporary file with arbitrary content
  • Delete file after use (can be disabled)
  • Send file to client, either inline or with save dialog, optionally with custom HTTP headers
  • Save file locally

Examples

<?php
use mikehaertl\tmp\File;

$file = new File('some content', '.html');

// send to client for download
$file->send('home.html');
// ... with custom content type (autodetected otherwhise)
$file->send('home.html', 'application/pdf');
// ... for inline display (download dialog otherwhise)
$file->send('home.html', 'application/pdf', true);
// ... with custom headers
$file->send('home.html', 'application/pdf', true, [
    'X-Header' => 'Example',
]);

// save to disk
$file->saveAs('/dir/test.html');

// Access file name and directory
echo $file->getFileName();
echo $file->getTempDir();

If you want to keep the temporary file, e.g. for debugging, you can set the $delete property to false:, (*3)

<?php
use mikehaertl\tmp\File;

$file = new File('some content', '.html');
$file->delete = false;

Default HTTP headers can also be added:, (*4)

<?php
use mikehaertl\tmp\File;

File::$defaultHeader['X-Header'] = 'My Default';

$file = new File('some content', '.html');
$file->send('home.html');

The $ignoreUserAbort option (on by default) mitigates an issue where the file was not deleted if the user closes the connection during a download. Try setting it to false if you experience unexpected behavior., (*5)

The Versions

28/08 2017

dev-master

9999999-dev

A convenience class for temporary files

  Sources   Download

MIT

by Michael HĂ€rtl

files

28/08 2017

1.1.1

1.1.1.0

A convenience class for temporary files

  Sources   Download

MIT

by Michael HĂ€rtl

files

11/05 2017

dev-fix-travis

dev-fix-travis

A convenience class for temporary files

  Sources   Download

MIT

by Michael HĂ€rtl

files

07/07 2016

1.1.0

1.1.0.0

A convenience class for temporary files

  Sources   Download

MIT

by Michael HĂ€rtl

files

09/07 2014

1.0.0

1.0.0.0

A convenience class for temporary files

  Sources   Download

MIT

by Michael Haertl

files