Cut PHP Code Review Time & Bugs into Half with CodeRabbit

Easily create, use and destroy temporary directories

spatie/temporary-directory image

spatie/temporary-directory stats

Downloads
36.7M
Stars
800
Open Issues
0
Forks
43

View on GitHub →

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
Join the Mastering Laravel community logo

Join the Mastering Laravel community

Connect with experienced developers in a friendly, noise-free environment. Get insights, share ideas, and find support for your coding challenges. Join us today and elevate your Laravel skills!

Join the Mastering Laravel community
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Shift logo

Shift

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

Shift