Skip to content
PHP library for file management
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

PHP File library

Latest Stable Version Latest Unstable Version License Codacy Badge Total Downloads Travis PSR2 PSR4 CodeCov

Versión en español

PHP library for file management.


This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.


The preferred way to install this extension is through Composer.

To install PHP File library, simply:

$ composer require Josantonius/File

The previous command will only install the necessary files, if you prefer to download the entire source code you can use:

$ composer require Josantonius/File --prefer-source

You can also clone the complete repository with Git:

$ git clone

Or install it manually:

Download File.php:

$ wget

Available Methods

Available methods in this library:

- Check if a file exists in a path or url:

Attribute Description Type Required Default
$file Path or file url. string Yes

# Return (boolean)

- Delete file if exists:

Attribute Description Type Required Default
$file File path. string Yes

# Return (boolean)

- Create directory if not exists:

Attribute Description Type Required Default
$path Path where to create directory. string Yes

# Return (boolean)

- Copy directory recursively:

File::copyDirRecursively($from, $to);
Attribute Description Type Required Default
$from Path from copy. string Yes
$to Path to copy. string Yes

# Return (boolean)

- Delete empty directory:

Attribute Description Type Required Default
$path Path to delete. string Yes

# Return (boolean)

- Delete directory recursively:

Attribute Description Type Required Default
$path Path to delete. string Yes

# Return (boolean)

- Get files from directory:

Attribute Description Type Required Default
$path Path where get file paths. string Yes

# Return (boolean)

Quick Start

To use this library with Composer:

require __DIR__ . '/vendor/autoload.php';

use Josantonius\File\File;

Or If you installed it manually, use it:

require_once __DIR__ . '/File.php';

use Josantonius\File\File;


Example of use for this library:

- Check if a local file exists:


- Check if a external file exists:


- Delete a local file:

File::delete(__DIR__ . '/test.txt');

- Create directory:

File::createDir(__DIR__ . '/test/');

- Delete empty directory:

File::deleteEmptyDir(__DIR__ . '/test/');

- Delete directory recursively:

File::deleteDirRecursively(__DIR__ . '/test/');

- Copy directory recursively:

File::copyDirRecursively(__DIR__ . '/test/', __DIR__ . '/copy/');

- Get file paths from directory:



To run tests you just need composer and to execute the following:

$ git clone

$ cd PHP-File

$ composer install

Run unit tests with PHPUnit:

$ composer phpunit

Run PSR2 code standard tests with PHPCS:

$ composer phpcs

Run PHP Mess Detector tests to detect inconsistencies in code style:

$ composer phpmd

Run all previous tests:

$ composer tests


  • Add new feature.
  • Improve tests.
  • Improve documentation.
  • Refactor code for disabled code style rules. See phpmd.xml and .php_cs.dist.


If you would like to help, please take a look at the list of issues or the To Do checklist.

Pull requests

  • Fork and clone.
  • Run the command composer install to install the dependencies. This will also install the dev dependencies.
  • Run the command composer fix to excute code standard fixers.
  • Run the tests.
  • Create a branch, commit, push and send me a pull request.


The file structure from this repository was created with PHP-Skeleton.


This project is licensed under MIT license. See the LICENSE file for more info.


2017 - 2018 Josantonius,

If you find it useful, let me know 😉

You can contact me on Twitter or through my email.

You can’t perform that action at this time.