PHPackages                             hellomohsinhello/temp-dir - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hellomohsinhello/temp-dir

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

hellomohsinhello/temp-dir
=========================

This package is useful for projects who requires to create temporary directories.

00PHP

Since Oct 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hellomohsinhello/temp-dir)[ Packagist](https://packagist.org/packages/hellomohsinhello/temp-dir)[ RSS](/packages/hellomohsinhello-temp-dir/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

This package is for learning purpose only. I have copied this package from \[spatie/temporary-directory\]
=========================================================================================================

[](#this-package-is-for-learning-purpose-only-i-have-copied-this-package-from-spatietemporary-directory)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PHP Composer](https://github.com/hellomohsinhello/temp-dir/actions/workflows/php.yml/badge.svg)](https://github.com/hellomohsinhello/temp-dir/actions/workflows/php.yml)

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

Here's a quick example on how to create a temporary directory and delete it:

```
use Hellomohsinhello\TempDir\TempDir;

$tempDir = (new TempDir())->create();

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

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

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require hellomohsinhello/temp-dir
```

Usage
-----

[](#usage)

### Creating a temporary directory

[](#creating-a-temporary-directory)

To create a temporary directory simply call the `create` method on a `TemporaryDirectory` object.

```
(new TempDir())->create();
```

Alternatively, use the static `make` method on a `TempDir` object.

```
TempDir::make();
```

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

### Naming your temporary directory

[](#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.

```
(new TempDir())
   ->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.

```
(new TempDir())
   ->name($name)
   ->force()
   ->create();
```

### Setting a custom location for a temporary directory

[](#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.

```
(new TempDir($location))
   ->create();
```

The `make` method also accepts a `$location` argument.

```
TempDir::make($location);
```

Finally, you can call the `location` method with a `$location` argument.

```
(new TempDir())
   ->location($location)
   ->create();
```

### Determining paths within the temporary directory

[](#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:

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

### Emptying a temporary directory

[](#emptying-a-temporary-directory)

Use the `empty` method to delete all the files inside the temporary directory.

```
$temporaryDirectory->empty();
```

### Deleting a temporary directory

[](#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.

```
$temporaryDirectory->delete();
```

### Deleting a temporary directory when the object is destroyed

[](#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.

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

    // ... use the temporary directory

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

handleTemporaryFiles();
```

You can also call `unset()` on an object instance.

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Mohsin Ali](https://github.com/hellomohsinhello)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

12

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1b02779f8ac2b82863e4874d4cfbe7d7bee8e9885a16aa5a672aa7c58f7ca4ed?d=identicon)[hellomohsinhello](/maintainers/hellomohsinhello)

---

Top Contributors

[![hellomohsinali](https://avatars.githubusercontent.com/u/26430360?v=4)](https://github.com/hellomohsinali "hellomohsinali (13 commits)")

### Embed Badge

![Health badge](/badges/hellomohsinhello-temp-dir/health.svg)

```
[![Health](https://phpackages.com/badges/hellomohsinhello-temp-dir/health.svg)](https://phpackages.com/packages/hellomohsinhello-temp-dir)
```

###  Alternatives

[yireo/magento2-googletagmanager2

Add Google Tag Manager to Magento

167930.4k5](/packages/yireo-magento2-googletagmanager2)[yaroslawww/laravel-force-https

Easy redirect to https for Laravel.

139.7k](/packages/yaroslawww-laravel-force-https)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
