PHPackages                             thomas-squall/file-utils - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. thomas-squall/file-utils

ActiveLibrary[File &amp; Storage](/categories/file-storage)

thomas-squall/file-utils
========================

Utilities for file management

0.2.8(3y ago)01361MITPHP

Since Aug 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ThomasSquall/PHPFileUtils)[ Packagist](https://packagist.org/packages/thomas-squall/file-utils)[ RSS](/packages/thomas-squall-file-utils/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (7)Used By (1)

File Utils for php
==================

[](#file-utils-for-php)

List of available functions
---------------------------

[](#list-of-available-functions)

1. [require\_all\_files](#require_all_files)
2. [require\_once\_all\_files](#require_once_all_files)
3. [include\_all\_files](#include_all_files)
4. [include\_once\_all\_files](#include_once_all_files)
5. [get\_all\_files](#get_all_files)
6. [get\_all\_dirs](#get_all_dirs)
7. [file\_get\_json](#file_get_json)
8. [file\_put\_json](#file_put_json)

### require\_all\_files

[](#require_all_files)

#### Description

[](#description)

Requires all the files in a folder that matches the provided pattern.

#### Definition

[](#definition)

require\_all\_files($dir, $pattern = "\*.php", $callback = null)

Where:

1. $dir is the directory where the files are located
2. $pattern is the pattern used to find the files (\*.php by default)
3. $recursive will fetch also the child folders if set to true (default is false)
4. $callback is the callback called per each file (null by default, the file path will be passed as parameter)

#### Usage

[](#usage)

```
function callback($file) {
    echo "file $file has been loaded..." . EOF;
}

require_all_fields("my/dir", "*.php", "callback");
```

### require\_once\_all\_files

[](#require_once_all_files)

#### Description

[](#description-1)

Requires once all the files in a folder that matches the provided pattern.

#### Definition

[](#definition-1)

require\_once\_all\_files($dir, $pattern = "\*.php", $callback = null)

Where:

1. $dir is the directory where the files are located
2. $pattern is the pattern used to find the files (\*.php by default)
3. $recursive will fetch also the child folders if set to true (default is false)
4. $callback is the callback called per each file (null by default, the file path will be passed as parameter)

#### Usage

[](#usage-1)

```
function callback($file) {
    echo "file $file has been loaded..." . EOF;
}

require_once_all_fields("my/dir", "*.php", "callback");
```

### include\_all\_files

[](#include_all_files)

#### Description

[](#description-2)

Includes all the files in a folder that matches the provided pattern.

#### Definition

[](#definition-2)

include\_all\_files($dir, $pattern = "\*.php", $callback = null)

Where:

1. $dir is the directory where the files are located
2. $pattern is the pattern used to find the files (\*.php by default)
3. $recursive will fetch also the child folders if set to true (default is false)
4. $callback is the callback called per each file (null by default, the file path will be passed as parameter)

#### Usage

[](#usage-2)

```
function callback($file) {
    echo "file $file has been loaded..." . EOF;
}

include_all_fields("my/dir", "*.php", "callback");
```

### include\_once\_all\_files

[](#include_once_all_files)

#### Description

[](#description-3)

Includes once all the files in a folder that matches the provided pattern.

#### Definition

[](#definition-3)

include\_once\_all\_files($dir, $pattern = "\*.php", $callback = null)

Where:

1. $dir is the directory where the files are located
2. $pattern is the pattern used to find the files (\*.php by default)
3. $recursive will fetch also the child folders if set to true (default is false)
4. $callback is the callback called per each file (null by default, the file path will be passed as parameter)

#### Usage

[](#usage-3)

```
function callback($file) {
    echo "file $file has been loaded..." . EOF;
}

include_once_all_files("my/dir", "*.php", "callback");
```

### get\_all\_files

[](#get_all_files)

#### Description

[](#description-4)

Get all the files in a folder that matches the provided pattern.

#### Definition

[](#definition-4)

get\_all\_files($dir, $recursive = false)

Where:

1. $dir is the directory where the files are located
2. $recursive will fetch also the children folders if set to true (default is false)

#### Usage

[](#usage-4)

```
print_r(get_all_files("my/dir"));
```

### get\_all\_dirs

[](#get_all_dirs)

#### Description

[](#description-5)

Returns all the directories in a given directory.

#### Definition

[](#definition-5)

get\_all\_dirs($dir, $recursive = false)

Where:

1. $dir is the directory where the files are located
2. $recursive will fetch also the children directories if set to true (default is false)

#### Usage

[](#usage-5)

```
print_r(get_all_files("my/dir"));
```

### file\_get\_json

[](#file_get_json)

#### Description

[](#description-6)

Reads the content of a json file and returns it as array or object. Please Note: if the content is not a json encoded string an empty array will be returned.

#### Definition

[](#definition-6)

file\_get\_json($file, $associative = true)

Where:

1. $file is the path to the file that we want to read
2. $associative will return the content as associative array when true, as object when false

#### Usage

[](#usage-6)

```
$my_array = file_get_json("my/dir/my_file.json");
```

### file\_put\_json

[](#file_put_json)

#### Description

[](#description-7)

Saves an array or an object into a json file.

#### Definition

[](#definition-7)

file\_put\_json($file, $content, $pretty = true)

Where:

1. $file is the path to the file that we want to save the content to
2. $content is the content we want to save (array or object)
3. $pretty will save the content prettified when true, minified when false

#### Usage

[](#usage-7)

```
$my_array = [
    'fruit_1' => 'apple',
    'fruit_2' => 'pear',
    'fruit_3' => 'orange'
];

file_put_json("my/dir/my_file.json", $my_array);
```

More utilities coming...
------------------------

[](#more-utilities-coming)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~212 days

Recently: every ~264 days

Total

6

Last Release

1405d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7748020?v=4)[Thomas Cocchiara](/maintainers/ThomasSquall)[@ThomasSquall](https://github.com/ThomasSquall)

---

Top Contributors

[![ThomasSquall](https://avatars.githubusercontent.com/u/7748020?v=4)](https://github.com/ThomasSquall "ThomasSquall (8 commits)")

### Embed Badge

![Health badge](/badges/thomas-squall-file-utils/health.svg)

```
[![Health](https://phpackages.com/badges/thomas-squall-file-utils/health.svg)](https://phpackages.com/packages/thomas-squall-file-utils)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

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