PHPackages                             asgard/file - 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. asgard/file

ActiveLibrary

asgard/file
===========

v0.3.1(10y ago)12.5k5MITPHPPHP &gt;=5.5.0

Since Sep 9Pushed 8y agoCompare

[ Source](https://github.com/asgardphp/file)[ Packagist](https://packagist.org/packages/asgard/file)[ RSS](/packages/asgard-file/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (5)

\#File

[![Build Status](https://camo.githubusercontent.com/0dba01ce29dbcabd9293823000d21806d9a1fa2fdaa9a2b8ad8ece2804284f9d/68747470733a2f2f7472617669732d63692e6f72672f6173676172647068702f66696c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/asgardphp/file)

File is a package to work with the file system and it provides a class to manipulate files as objects.

- [Installation](#installation)
- [FileSystem](#filesystem)
- [File](#file)

\##Installation **If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries.**

```
composer require asgard/file 0.*

```

\##FileSystem

\###$mode

When a method takes a parameter $mode, you can use different values:

```
$mode = \Asgard\File\FileSystem::OVERRIDE; #override existing files
$mode = \Asgard\File\FileSystem::RENAME; #rename new files
$mode = \Asgard\File\FileSystem::IGNORE; #ignore existing files
$mode = \Asgard\File\FileSystem::MERGEDIR; #merge directories
$mode = \Asgard\File\FileSystem::MERGEDIR | \Asgard\File\FileSystem::OVERRIDE; #merge directories but override existing files
$mode = \Asgard\File\FileSystem::MERGEDIR | \Asgard\File\FileSystem::RENAME; #merge directories but rename new files
$mode = \Asgard\File\FileSystem::MERGEDIR | \Asgard\File\FileSystem::IGNORE; #merge directories but ignore existing files

```

It defaults to OVERRIDE.

\###Methods

Get relative path from a file to another:

```
\Asgard\File\FileSystem::relativeTo($from, $to);

```

Get a new filename if the existing one is already taken:

```
$filename = \Asgard\File\FileSystem::getNewFilename($filename);

```

Rename a file or directory:

```
$path = \Asgard\File\FileSystem::rename($src, $dst, $mode=null);

```

returns the new path if successful, otherwise false.

Copy a file or directory:

```
$path = \Asgard\File\FileSystem::copy($src, $dst, $mode=null);

```

returns the new path if successful, otherwise false.

Delete a file or directory:

```
\Asgard\File\FileSystem::delete($path);

```

returns true is successful, otherwise false.

Create a new directory:

```
\Asgard\File\FileSystem::mkdir($path);

```

returns true is successful, otherwise false.

Write content into a file:

```
\Asgard\File\FileSystem::write($path, $content, $mode=null, $append=false);

```

returns true is successful, otherwise false.

\##File

Instance:

```
$file = new \Asgard\File\File('/path/to/file.txt');

```

Set source:

```
$file->setSrc('/path/to/another/file.txt');

```

Set file name:

```
$file->setName('file2.txt');

```

Get file name:

```
$file->getName();

```

Check if the file was just uploaded:

```
$file->isUploaded();

```

Get the file size in bytes:

```
$file->size();

```

Get the file type:

```
$file->type();

```

Get the file extension:

```
$file->extension();

```

Check if the file exists:

```
$file->exists();

```

Get the file source:

```
$file->src();

```

Get the relative path to another file or directory:

```
$file->relativeTo('/another/file.jpg');

```

Move the to another directory:

```
$file->moveToDir('/a/dir/', $mode=null);

```

Check if the file is in a directory

```
$file->isIn('/a/dir/');

```

Check if the file is at a specific path:

```
$file->isAt('/path/to/file.txt');

```

Rename the file:

```
$file->rename('/anoter/path/to/file.txt', $mode=null);

```

Delete the file:

```
$file->delete();

```

Copy the file:

```
$file->copy('/path/to/copy.txt', $mode=null);

```

\###Contributing

Please submit all issues and pull requests to the [asgardphp/asgard](http://github.com/asgardphp/asgard) repository.

### License

[](#license)

The Asgard framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity51

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

Total

4

Last Release

3655d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.4.0

v0.3.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/352850?v=4)[leyou](/maintainers/leyou)[@leyou](https://github.com/leyou)

---

Top Contributors

[![h0gar](https://avatars.githubusercontent.com/u/439138?v=4)](https://github.com/h0gar "h0gar (42 commits)")

### Embed Badge

![Health badge](/badges/asgard-file/health.svg)

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

PHPackages © 2026

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