PHPackages                             atk14/files - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. atk14/files

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

atk14/files
===========

A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management

v1.6.12(1mo ago)053.8k↑53.2%117MITPHPPHP &gt;=5.6CI passing

Since Jan 23Pushed 3w ago2 watchersCompare

[ Source](https://github.com/atk14/Files)[ Packagist](https://packagist.org/packages/atk14/files)[ Docs](https://github.com/atk14/Files)[ RSS](/packages/atk14-files/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (23)Used By (17)

Files
=====

[](#files)

[![Tests](https://github.com/atk14/Files/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/atk14/Files/actions/workflows/tests.yml)

A PHP class providing static methods for common file system operations: reading and writing files, copying, moving, deleting, MIME type detection, image size detection, finding files, and managing permissions.

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

[](#installation)

```
composer require atk14/files

```

Usage
-----

[](#usage)

All methods follow the same error-reporting convention — pass `$error` and `$error_str` by reference to check for failures without exceptions:

```
$content = Files::GetFileContent("/path/to/file", $error, $error_str);
if ($error) {
    echo $error_str; // "file.txt is not a file"
}

```

Both parameters are optional.

### Reading and writing

[](#reading-and-writing)

```
$content = Files::GetFileContent("/path/to/file");

Files::WriteToFile("/path/to/file", $content);
Files::AppendToFile("/path/to/file", $content);
Files::EmptyFile("/path/to/file");
Files::TouchFile("/path/to/file");

```

`WriteToCacheFile()` writes atomically via a temporary file and rename, preventing partial reads in concurrent situations:

```
Files::WriteToCacheFile("/path/to/cache/file", $content);

```

### Copying, moving and deleting

[](#copying-moving-and-deleting)

```
Files::CopyFile("/path/to/source", "/path/to/target");

// move a file into an existing directory
Files::MoveFile("/path/to/file.jpg", "/path/to/dir/");
// move a file to a new name
Files::MoveFile("/path/to/old.jpg", "/path/to/new.jpg");

Files::Unlink("/path/to/file");
Files::RecursiveUnlinkDir("/path/to/dir");

```

### Directories

[](#directories)

```
Files::Mkdir("/path/to/new/directory");         // creates all missing parent directories
Files::MkdirForFile("/path/to/new/file.txt");   // creates "/path/to/new"

```

### Temporary files

[](#temporary-files)

```
$tmp = Files::WriteToTemp($content);    // write content to a new temp file
$tmp = Files::CopyToTemp("/path/to/source");
// ... work with $tmp ...
Files::Unlink($tmp);

$path = Files::GetTempFilename();                   // just reserve a filename
$path = Files::GetTempFilename("my_prefix_");       // with a custom prefix

echo Files::GetTempDir();   // e.g. "/tmp"

```

The temporary directory defaults to `sys_get_temp_dir()`. Define the `TEMP` constant before including the library to override it:

```
define("TEMP", "/path/to/temp/");

```

### MIME type detection

[](#mime-type-detection)

```
$mime = Files::DetermineFileType("/path/to/file");  // e.g. "image/jpeg"

// for uploaded files, pass the original filename to improve detection accuracy
$mime = Files::DetermineFileType(
    $_FILES["file"]["tmp_name"],
    ["original_filename" => $_FILES["file"]["name"]],
    $preferred_suffix  // e.g. "jpg"
);

```

Detection uses `mime_content_type()`, `finfo`, or the `file` shell command as fallbacks. When [Imagick](https://www.php.net/manual/en/book.imagick.php) is available it is used as a last resort.

### Image dimensions

[](#image-dimensions)

```
[$width, $height] = Files::GetImageSize("/path/to/image.jpg");
[$width, $height] = Files::GetImageSizeByContent($binary_image_data);

```

### Finding files

[](#finding-files)

```
// all files recursively
$files = Files::FindFiles("./dir");

// only immediate children
$files = Files::FindFiles("./dir", ["maxdepth" => 1]);

// filter by name pattern
$images = Files::FindFiles("./dir", ["pattern" => '/\.(png|jpg)$/i']);

// filter by modification time
$recent = Files::FindFiles("./log", [
    "pattern"  => '/\.log$/',
    "min_mtime" => time() - 30 * 60,    // not older than 30 minutes
    "max_mtime" => time(),
]);

```

### Permissions

[](#permissions)

New files are created with `0666`, new directories with `0777` (both subject to the process umask). Override the defaults globally:

```
define("FILES_DEFAULT_FILE_PERMS", 0640);
define("FILES_DEFAULT_DIR_PERMS", 0750);

```

Or at runtime:

```
$prev = Files::SetDefaultFilePerms(0640);
// ... do some work ...
Files::SetDefaultFilePerms($prev);

```

Apply the current defaults to an existing file or directory:

```
Files::NormalizeFilePerms("/path/to/file");

```

Check whether a file is both readable and writable by the current process:

```
if (!Files::IsReadableAndWritable("/path/to/file")) {
    // ...
}

```

Validate an HTTP-uploaded file:

```
if (!Files::IsUploadedFile($_FILES["file"]["tmp_name"])) {
    // reject — not a legitimate upload
}

```

Licence
-------

[](#licence)

Files is free software distributed [under the terms of the MIT license](http://www.opensource.org/licenses/mit-license)

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance93

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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 ~170 days

Recently: every ~4 days

Total

21

Last Release

45d ago

PHP version history (2 changes)v1.0PHP &gt;=5.3.0

v1.6.9PHP &gt;=5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/974278?v=4)[Jaromir Tomek](/maintainers/yarri)[@yarri](https://github.com/yarri)

---

Top Contributors

[![yarri](https://avatars.githubusercontent.com/u/974278?v=4)](https://github.com/yarri "yarri (109 commits)")

---

Tags

filesystemmimefilefilespermissionsupload

### Embed Badge

![Health badge](/badges/atk14-files/health.svg)

```
[![Health](https://phpackages.com/badges/atk14-files/health.svg)](https://phpackages.com/packages/atk14-files)
```

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k679.9M2.5k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.7k285.7M1.0k](/packages/league-flysystem-aws-s3-v3)[league/flysystem-local

Local filesystem adapter for Flysystem.

225267.1M89](/packages/league-flysystem-local)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8737.3M276](/packages/league-flysystem-memory)[league/flysystem-sftp-v3

SFTP filesystem adapter for Flysystem.

6134.8M156](/packages/league-flysystem-sftp-v3)[league/flysystem-ziparchive

ZIP filesystem adapter for Flysystem.

1099.8M73](/packages/league-flysystem-ziparchive)

PHPackages © 2026

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