PHPackages                             martinmuzatko/filehandler - 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. martinmuzatko/filehandler

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

martinmuzatko/filehandler
=========================

Creating, Reading, Writing, Deleting Files &amp; More, see https://github.com/MartinMuzatko/FileHandler

v2.0.0(10y ago)027MITPHPPHP &gt;=5.3.0

Since Sep 9Pushed 10y ago1 watchersCompare

[ Source](https://github.com/MartinMuzatko/FileHandler)[ Packagist](https://packagist.org/packages/martinmuzatko/filehandler)[ Docs](https://github.com/MartinMuzatko/FileHandler)[ RSS](/packages/martinmuzatko-filehandler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

FileHandler
===========

[](#filehandler)

As lazy I am, when it comes to php function redundancy, I prefer to create my own tools rather than retyping the entire file open call over and over again.

I am using this self-made FileHandler for years now, and I still can't find a viable alternative.

Optional Requirements
=====================

[](#optional-requirements)

Make sure to enable finfo (fileinfo) php extension to get `mimetype` and `encoding` in `FileHandler::getInfo`

Installing
==========

[](#installing)

**Via Composer:**

```
php composer.phar require martinmuzatko/filehandler

```

or add it as dependency:

```
"require": {
	"martinmuzatko/filehandler": "*"
}

```

Usage
=====

[](#usage)

Include the files or use autoloader.

```
use martinmuzatko\filehandler\File;
use martinmuzatko\filehandler\Handler as FileHandler;
```

Using the methods below, you can easily create, write, rename, read files. While **FileHandler** is a set of static methods, **File** serves a convenient way of quickly modifying files.

FileHandler Examples
--------------------

[](#filehandler-examples)

**Checking Image Dimensions**

```
$file = 'path/to/image.jpg';
$info = FileHandler::getInfo($file);
if ($info->width > 1920 || $info->height > 1080)
{
  echo 'File '.$info->basename.' is too big, resize it to 1920x1080';
}
```

File Examples
-------------

[](#file-examples)

**Batch creating customer directories**

```
$customers = ['01-jake', '02-mike', '03-francis', '04-martin', '05-jane'];
foreach ($customers as $customer)
{
	$file = new File($customer.'/info.json');
	$file
		->create()
		->write('[{ title: "Read instructions."}]')
		->chmod(0644);
}
```

Constants
=========

[](#constants)

- TAB
- Linefeed (LF)
- Carriage Return (CR)
- Windows Combination (CRLF)

Methods
=======

[](#methods)

FileHandler (Static)
--------------------

[](#filehandler-static)

Methods are called statically (FileHandler::getInfo())

### getInfo($file)

[](#getinfofile)

Return fileinformation as object Example:

```
$info = FileHandler::getInfo($file); echo $info->writable;
```

Returns these informations:

**Paths**

- dirname
- basename
- extension
- filename
- path

**Dimensions**

- width
- height

**Timestamps and other Properties**

- created
- modified
- size
- type
- mimetype (only with finfo enabled)
- encoding (only with finfo enabled)

**Permissions**

- owner
- group
- perms

**Checks - Boolean**

- writable
- readable
- exists
- isfile
- isdir
- islink

### getAsArray($file)

[](#getasarrayfile)

Returns file content as array.

### read($file)

[](#readfile)

Return File as string if it exists

### write($file, $content, $seperator = CRLF)

[](#writefile-content-seperator--crlf)

Overwrites File with given string or array, returns true if succeeded.

### create($file, $content = '')

[](#createfile-content--)

Creates File but does not overwrite existing files.

### delete($file)

[](#deletefile)

Delete file if existing.

### rename($old, $new)

[](#renameold-new)

Rename a File from old path to new path

### appendFile($targetFile, $file, $seperator = CRLF)

[](#appendfiletargetfile-file-seperator--crlf)

Appends $file to $targetFile with given seperator.

### appendLine($targetFile, $content, $seperator = CRLF)

[](#appendlinetargetfile-content-seperator--crlf)

Appends $content to $targetFile with a defined $seperator

### clearFile($file)

[](#clearfilefile)

Clears file from any content

### listFiles($path = '.', $includeFiles = true, $includeFolders = true)

[](#listfilespath---includefiles--true-includefolders--true)

List all files within a valid directory as array

File (Method Chaining)
----------------------

[](#file-method-chaining)

The constructor and some other methods accepts any of these:

- Instance of File
- String (Paths)
- Resources (Handles retrieved by `fopen()`)
- Any other kind of File Stream

After constructing, the File contains ANY info retrievable via `FileHandler::getInfo()`e.g.

```
$f = new File('index.php'); $f->writable;
```

\###create() Create file, accepts no param, file is entered via constructur:`new File('path/to/file');`\###copy($target)

\###delete()

\###rename($name)

\###move($target) Moving file to desired location, will automatically create all directories needed for new location example:

```
$f = new File('index.php');
$f->move('path/to/new/');
```

will move index.php to `path/to/new` and will create the folders `./path`, `./path/to` and `./path/to/new`

\###chmod($octet) Changing the file permissions from 0111 to 0777 ###merge($target) *work in progress*

\###read() Get file contents. Method chaining after calling this method is not possible anymore.

\###concat($content, $separator = CRLF) Adding content to a file.

\###write($content) Write as in overwrite (use concat if you want to add to the file instead of overwriting)

\###find($lookup) Find files in a directory, regex enabled. Retrievable via `$file = new File(); $file->find(); $file->selection;` or `$file->getSelected()`

\####EXAMPLES: #####Find by string:

```
find('item.png')

```

---

\#####Find by Regex:

```
find('/[\w]*$/')

```

---

\#####Find by Property - Value pairs with operators:

`find(['mimetype' => 'image/png'])` - find all files of mimetype image/png

`find(['size' => '1441000000'])` - fild all files newer than 31.08.2015

`find(['mimetype' => '!directory'])` - fild all non-directory files

---

\####Operators: &lt;, &gt;, &lt;=, &gt;=, ! ####Properties are used by getInfo()

\###get() This method is used as final method to get selections made by find() or select() or new File() Returns path if no selection is done.

\###select() Selecting files by paths array of paths array of Files array of File Selections You can also mix these ####Examples

---

```
$file->select('file.png');

```

`$file->select(['file.png', 'another.jpg', 'file.avi']);`

`$file->select([['file.png', 'another.jpg'], 'file.avi']);`

`$file->select([$file->find(), 'customers/file.txt']);`

```
$file->select($file);

```

---

Any array or array of arrays will be traversed down to create an one-dimensional array saved to public property $selection. Selections are retrievable by **get()**

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

3891d ago

Major Versions

v1.0.0 → v2.0.02015-09-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/66aa6189b04ad0f92a3cabbf1a485c7e9412a37b91c755ec1cc9ce7bd7b34ca2?d=identicon)[MartinMuzatko](/maintainers/MartinMuzatko)

---

Top Contributors

[![MartinMuzatko](https://avatars.githubusercontent.com/u/2950505?v=4)](https://github.com/MartinMuzatko "MartinMuzatko (36 commits)")

---

Tags

filefilehandlerfilehandling

### Embed Badge

![Health badge](/badges/martinmuzatko-filehandler/health.svg)

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

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.1k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M788](/packages/league-flysystem-aws-s3-v3)[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[knplabs/knp-gaufrette-bundle

Allows to easily use the Gaufrette library in a Symfony project

72528.6M91](/packages/knplabs-knp-gaufrette-bundle)[league/flysystem-local

Local filesystem adapter for Flysystem.

226231.8M39](/packages/league-flysystem-local)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8533.6M194](/packages/league-flysystem-memory)

PHPackages © 2026

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