Temporary Directory

spatie/temporary-directory image

Temporary Directory stats

Downloads
36.7M
Stars
800
Open Issues
0
Forks
43

View on GitHub →

Easily create, use and destroy temporary directories

Summary of Spatie's TemporaryDirectory Laravel Package

The spatie/temporary-directory package provides a simple and efficient way to create, manage, and dispose of temporary directories within a Laravel application. This utility is particularly useful when handling temporary files during data processing, ensuring a clean and isolated environment that automatically cleans up after operations.

Key Features

  • Easy Creation and Deletion: Quickly create and delete temporary directories.
  • Custom Naming and Location: Set custom names and specify the location for temporary directories.
  • Automatic Cleanup: Option to automatically delete the directory when the object is destroyed.
  • Path Management: Conveniently determine paths within the temporary directory.

Installation

Install the package via Composer:

composer require spatie/temporary-directory

Usage Examples

Basic Temporary Directory Creation

use Spatie\TemporaryDirectory\TemporaryDirectory;
 
$temporaryDirectory = (new TemporaryDirectory())->create();

Custom Directory Naming

$temporaryDirectory = (new TemporaryDirectory())
->name('my-temp-dir')
->create();

Custom Location and Force Creation

$temporaryDirectory = (new TemporaryDirectory('path/to/location'))
->name('my-temp-dir')
->force()
->create();

Automatic Cleanup

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

Path Determination Within Temporary Directory

$path = $temporaryDirectory->path('subfolder/file.txt');

Deleting the Temporary Directory

$temporaryDirectory->delete();

Additional Information

  • Testing: Run composer test to execute tests.
  • Contributions: Contributions are welcome via pull requests and issues.
  • License: The package is open-sourced under the MIT license.

This package not only simplifies file handling tasks but also encourages clean coding practices by managing temporary data efficiently. Whether you're handling user uploads, generating temporary data during tests, or processing large datasets, spatie/temporary-directory offers a robust solution to manage temporary files in Laravel applications.

spatie photo

We create open source, digital products and courses for the developer community

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Spatie Temporary Directory Related Articles

Easily Manage Temporary Files in Laravel image

Easily Manage Temporary Files in Laravel

Read article
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel