PHP code example of spatie / temporary-directory

1. Go to this page and download the library: Download spatie/temporary-directory 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/ */

    

spatie / temporary-directory example snippets


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();

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

TemporaryDirectory::make();

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

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

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

TemporaryDirectory::make($location);

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

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

$temporaryDirectory->empty();

$temporaryDirectory->delete();

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

    // ... use the temporary directory

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

handleTemporaryFiles();