2017 © Pedro Peláez
 

library temporary-directory

Easily create, use and destroy temporary directories

image

spatie/temporary-directory

Easily create, use and destroy temporary directories

  • Tuesday, May 22, 2018
  • by Spatie
  • Repository
  • 6 Watchers
  • 231 Stars
  • 875,978 Installations
  • PHP
  • 19 Dependents
  • 0 Suggesters
  • 12 Forks
  • 1 Open issues
  • 13 Versions
  • 26 % Grown

The README.md

Quickly create, use and delete temporary directories

Latest Version on Packagist Tests Software License Total Downloads, (*1)

This package allows you to quickly create, use and delete a temporary directory in the system's temporary directory., (*2)

Here's a quick example on how to create a temporary directory and delete it:, (*3)

use Spatie\TemporaryDirectory\TemporaryDirectory;

$temporaryDirectory = (new TemporaryDirectory())->create();

// Get a path inside the temporary directory
$temporaryDirectory->path('temporaryfile.txt');

// Delete the temporary directory and all the files inside it
$temporaryDirectory->delete();

Support us

, (*4)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*5)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*6)

Installation

You can install the package via composer:, (*7)

composer require spatie/temporary-directory

Usage

Creating a temporary directory

To create a temporary directory simply call the create method on a TemporaryDirectory object., (*8)

(new TemporaryDirectory())->create();

Alternatively, use the static make method on a TemporaryDirectory object., (*9)

TemporaryDirectory::make();

By default, the temporary directory will be created in a timestamped directory in your system's temporary directory (usually /tmp)., (*10)

Naming your temporary directory

If you want to use a custom name for your temporary directory instead of the timestamp call the name method with a string $name argument before the create method., (*11)

(new TemporaryDirectory())
   ->name($name)
   ->create();

By default an exception will be thrown if a directory already exists with the given argument. You can override this behaviour by calling the force method in combination with the name method., (*12)

(new TemporaryDirectory())
   ->name($name)
   ->force()
   ->create();

Setting a custom location for a temporary directory

You can set a custom location in which your temporary directory will be created by passing a string $location argument to the TemporaryDirectory constructor., (*13)

(new TemporaryDirectory($location))
   ->create();

The make method also accepts a $location argument., (*14)

TemporaryDirectory::make($location);

Finally, you can call the location method with a $location argument., (*15)

(new TemporaryDirectory())
   ->location($location)
   ->create();

Determining paths within the temporary directory

You can use the path method to determine the full path to a file or directory in the temporary directory:, (*16)

$temporaryDirectory = (new TemporaryDirectory())->create();
$temporaryDirectory->path('dumps/datadump.dat'); // return  /tmp/1485941876276/dumps/datadump.dat

Emptying a temporary directory

Use the empty method to delete all the files inside the temporary directory., (*17)

$temporaryDirectory->empty();

Deleting a temporary directory

Once you're done processing your temporary data you can delete the entire temporary directory using the delete method. All files inside of it will be deleted., (*18)

$temporaryDirectory->delete();

Deleting a temporary directory when the object is destroyed

If you want to automatically have the filesystem directory deleted when the object instance has no more references in its defined scope, you can enable deleteWhenDestroyed() on the TemporaryDirectory object., (*19)

function handleTemporaryFiles()
{
    $temporaryDirectory = (new TemporaryDirectory())
        ->deleteWhenDestroyed()
        ->create();

    // ... use the temporary directory

    return; // no need to manually call $temporaryDirectory->delete()!
}

handleTemporaryFiles();

You can also call unset() on an object instance., (*20)

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently., (*21)

Contributing

Please see CONTRIBUTING for details., (*22)

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities., (*23)

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using., (*24)

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium., (*25)

We publish all received postcards on our company website., (*26)

Credits

License

The MIT License (MIT). Please see License File for more information., (*27)

The Versions

22/05 2018

dev-master

9999999-dev https://github.com/spatie/temporary-directory

Easily create, use and destroy temporary directories

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

12/04 2018

1.1.4

1.1.4.0 https://github.com/spatie/temporary-directory

Easily create, use and destroy temporary directories

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

23/02 2018

dev-add-autodestruct

dev-add-autodestruct https://github.com/spatie/temporary-directory

Easily create, use and destroy temporary directories

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie temporary-directory

21/12 2017

dev-analysis-8AxJ2B

dev-analysis-8AxJ2B https://github.com/spatie/temporary-directory

Easily create, use and destroy temporary directories

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie temporary-directory

11/09 2017

1.1.3

1.1.3.0 https://github.com/spatie/temporary-directory

Easily create, use and destroy temporary directories

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

02/02 2017

1.1.2

1.1.2.0 https://github.com/spatie/temporary-directory

The `temporary-directory` package allows you to easily create, use and destroy temporary directories.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

02/02 2017

1.1.1

1.1.1.0 https://github.com/spatie/temporary-directory

The `temporary-directory` package allows you to easily create, use and destroy temporary directories.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

01/02 2017

1.1.0

1.1.0.0 https://github.com/spatie/temporary-directory

The `temporary-directory` package allows you to easily create, use and destroy temporary directories.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

01/02 2017

1.0.0

1.0.0.0 https://github.com/spatie/temporary-directory

The `temporary-directory` package allows you to easily create, use and destroy temporary directories.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

01/02 2017

0.0.3

0.0.3.0 https://github.com/spatie/temporary-directory

The `temporary-directory` package allows you to easily create, use and destroy temporary directories.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

31/01 2017

dev-analysis-zeNEj9

dev-analysis-zeNEj9 https://github.com/spatie/temporary-directory

The `temporary-directory` package allows you to easily create, use and destroy temporary directories.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

31/01 2017

0.0.2

0.0.2.0 https://github.com/spatie/temporary-directory

The `temporary-directory` package allows you to easily create, use and destroy temporary directories.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory

31/01 2017

0.0.1

0.0.1.0 https://github.com/spatie/temporary-directory

The `temporary-directory` package allows you to easily create, use and destroy temporary directories.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

spatie temporary-directory