PHPackages                             kartik-v/yii2-filesystem - 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. kartik-v/yii2-filesystem

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

kartik-v/yii2-filesystem
========================

File system utilities for managing files and folders including reading, writing and appending to files

65.3k↓24.5%3[1 issues](https://github.com/kartik-v/yii2-filesystem/issues)PHP

Since Nov 21Pushed 7y ago3 watchersCompare

[ Source](https://github.com/kartik-v/yii2-filesystem)[ Packagist](https://packagist.org/packages/kartik-v/yii2-filesystem)[ RSS](/packages/kartik-v-yii2-filesystem/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

 [ ![Krajee Logo](https://camo.githubusercontent.com/4addfbb3869c3fc7d79befea4f06d9cf3655a686fb503df0da1d725859cfdef9/687474703a2f2f6b617274696b2d762e6769746875622e696f2f626f6f7473747261702d66696c65696e7075742d73616d706c65732f73616d706c65732f6b72616a65652d6c6f676f2d622e706e67) ](http://demos.krajee.com "Krajee Demos")
 yii2-filesystem ---

 [ ![Donate](https://camo.githubusercontent.com/4af77d425ca202e55ab3d711b438e238ded194735bc345a019ac060e03e26227/687474703a2f2f6b617274696b2d762e6769746875622e696f2f626f6f7473747261702d66696c65696e7075742d73616d706c65732f73616d706c65732f646f6e6174652e706e67) ](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DTP3NZQ6G2AYU "Donate via Paypal")
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#------------------------yii2-filesystem--------------------)

[![Latest Stable Version](https://camo.githubusercontent.com/d66eb3a3ffc813dd7faa0f35ecc6763311de65198ee2026af0568b50d76dfc29/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d66696c6573797374656d2f762f737461626c65)](https://packagist.org/packages/kartik-v/yii2-filesystem)[![Latest Unstable Version](https://camo.githubusercontent.com/05562d1b357a1e4fbc19aa5321497fc64fe779d0622b4566eb431640eac897fa/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d66696c6573797374656d2f762f756e737461626c65)](https://packagist.org/packages/kartik-v/yii2-filesystem)[![License](https://camo.githubusercontent.com/52e0f07d93ab0bbd789372fdd9210b9e30d9b01c51cff0a14995f2e910c7b998/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d66696c6573797374656d2f6c6963656e7365)](https://packagist.org/packages/kartik-v/yii2-filesystem)[![Total Downloads](https://camo.githubusercontent.com/3c389c2c438e27f15d71d192b4635858f382b7dc472ea8e09663d5c054212945/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d66696c6573797374656d2f646f776e6c6f616473)](https://packagist.org/packages/kartik-v/yii2-filesystem)[![Monthly Downloads](https://camo.githubusercontent.com/54c3cfb20181739622ece17ac81e00fd0d8eac8a8b288a82ed0ceaf0bd1db0cf/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d66696c6573797374656d2f642f6d6f6e74686c79)](https://packagist.org/packages/kartik-v/yii2-filesystem)[![Daily Downloads](https://camo.githubusercontent.com/2e183e82632c88faa1036fd5535e9fbb3fad8dbbca1b44d5dae77dd9910cc50d/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d66696c6573797374656d2f642f6461696c79)](https://packagist.org/packages/kartik-v/yii2-filesystem)

File system utilities for managing files and folders including reading, writing and appending to files. It also includes a `Resumable` component that provides an object oriented backend to manage resumable and chunk file uploads via resumable.js.

### Install

[](#install)

Either run

```
$ php composer.phar require kartik-v/yii2-filesystem "@dev"

```

or add

```
"kartik-v/yii2-filesystem": "@dev"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

Example showing creation of a folder instance and search for all the .csv files within it:

```
use kartik\filesystem\Folder;

$dir = new Folder('/path/to/folder');
$files = $dir->find('.*\.csv');
```

Now you can loop through the files and read from or write/append to the contents or simply delete the file:

```
use kartik\filesystem\File;

foreach ($files as $file) {
    $file = new File($dir->pwd() . DIRECTORY_SEPARATOR . $file);
    $contents = $file->read();
    // $file->write('I am overwriting the contents of this file');
    // $file->append('I am adding to the bottom of this file.');
    // $file->delete(); // I am deleting this file
    $file->close(); // Be sure to close the file when you're done
}
```

Examples
--------

[](#examples)

```
use kartik\filesystem\Folder;
use kartik\filesystem\File;

/**
 * Create a new folder with 0755 permissions
 */
$dir = new Folder('/path/to/folder', true, 0755);

/**
 * Create a new file with 0644 permissions
 */
$file = new File('/path/to/file.php', true, 0644);

/**
 * addPathElement: Returns $path with $element added, with correct slash in-between.
 */
$path = Folder::addPathElement('/a/path/for', 'testing');
// $path equals /a/path/for/testing

/**
 * cd: Change directory to $path. Returns false on failure.
 */
$folder = new Folder('/foo');
echo $folder->path; // Prints /foo
$folder->cd('/bar');
echo $folder->path; // Prints /bar
$false = $folder->cd('/non-existent-folder');

/**
 * chmod: Change the mode on a directory structure recursively.
 *        This includes changing the mode on files as well.
 */
$dir = new Folder();
$dir->chmod('/path/to/folder', 0644, true, ['skip_me.php']);

/**
 * copy: Recursively copy a directory.
 */
$folder1 = new Folder('/path/to/folder1');
$folder1->copy('/path/to/folder2');
// Will put folder1 and all its contents into folder2

$folder = new Folder('/path/to/folder');
$folder->copy([
    'to' => '/path/to/new/folder',
    'from' => '/path/to/copy/from', // Will cause a cd() to occur
    'mode' => 0755,
    'skip' => ['skip-me.php', '.git'],
    'scheme' => Folder::SKIP  // Skip directories/files that already exist.
]);

/**
 * create: Create a directory structure recursively. Can be used to create
 *         deep path structures like /foo/bar/baz/shoe/horn
 */
$folder = new Folder();
if ($folder->create('foo' . DS . 'bar' . DS . 'baz' . DS . 'shoe' . DS . 'horn')) {
    // Successfully created the nested folders
}

/**
 * delete: Recursively remove directories if the system allows.
 */
$folder = new Folder('foo');
if ($folder->delete()) {
    // Successfully deleted foo and its nested folders
}

/**
 * find: Returns an array of all matching files in the current directory.
 */
// Find all .png in your webroot/img/ folder and sort the results
$dir = new Folder(WWW_ROOT . 'img');
$files = $dir->find('.*\.png', true);
/*
Array
(
    [0] => cake.icon.png
    [1] => test-error-icon.png
    [2] => test-fail-icon.png
    [3] => test-pass-icon.png
    [4] => test-skip-icon.png
)
*/

/**
 * findRecursive: Returns an array of all matching files in and below the current directory.
 */
// Recursively find files beginning with test or index
$dir = new Folder(WWW_ROOT);
$files = $dir->findRecursive('(test|index).*');
/*
Array
(
    [0] => /var/www/demo/index.php
    [1] => /var/www/demo/test.php
    [2] => /var/www/demo/img/test-skip-icon.png
    [3] => /var/www/demo/img/test-fail-icon.png
    [4] => /var/www/demo/img/test-error-icon.png
    [5] => /var/www/demo/img/test-pass-icon.png
)
*/

/**
 * read: Returns an array of the contents of the current directory. The returned
 *       array holds two sub arrays: One of directories and one of files.
 */
// Recursively find files beginning with test or index
$dir = new Folder(WWW_ROOT);
$files = $dir->findRecursive('(test|index).*');
/*
Array
(
    [0] => /var/www/demo/index.php
    [1] => /var/www/demo/test.php
    [2] => /var/www/demo/img/test-skip-icon.png
    [3] => /var/www/demo/img/test-fail-icon.png
    [4] => /var/www/demo/img/test-error-icon.png
    [5] => /var/www/demo/img/test-pass-icon.png
)
*/
```

License
-------

[](#license)

**yii2-filesystem** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

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://avatars.githubusercontent.com/u/3592619?v=4)[Kartik Visweswaran](/maintainers/kartik-v)[@kartik-v](https://github.com/kartik-v)

---

Top Contributors

[![kartik-v](https://avatars.githubusercontent.com/u/3592619?v=4)](https://github.com/kartik-v "kartik-v (6 commits)")

---

Tags

filefilesystemfolderkrajeeyii2

### Embed Badge

![Health badge](/badges/kartik-v-yii2-filesystem/health.svg)

```
[![Health](https://phpackages.com/badges/kartik-v-yii2-filesystem/health.svg)](https://phpackages.com/packages/kartik-v-yii2-filesystem)
```

###  Alternatives

[ericnorris/amazon-s3-php

A lightweight and fast S3 client for PHP.

2147.0k](/packages/ericnorris-amazon-s3-php)

PHPackages © 2026

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