PHPackages                             imran/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. [File &amp; Storage](/categories/file-storage)
4. /
5. imran/file

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

imran/file
==========

A PHP class to work with files.

1.0.0(3y ago)010MITPHPPHP &gt;=8.0

Since Feb 22Pushed 3y ago1 watchersCompare

[ Source](https://github.com/grim-reapper/file)[ Packagist](https://packagist.org/packages/imran/file)[ RSS](/packages/imran-file/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (2)Versions (2)Used By (0)

File Handling
=============

[](#file-handling)

The `File` class is a PHP class that provides a convenient and easy-to-use API for working with files and directories in PHP. With this class, you can perform a wide range of file-related operations, such as reading and writing to files, creating and deleting directories, moving and copying files, and more.

All the methods in this class are static methods, meaning that you can use them without creating an instance of the class. This makes it easy to use the class from anywhere in your code.

Overall, the File class provides a powerful and user-friendly API for working with files and directories in PHP. Whether you're a beginner or an experienced PHP developer, this class is a valuable tool for simplifying file-related tasks and improving the reliability and performance of your code.

Features
--------

[](#features)

- `exists`: Check if a file or directory exists
- `get`: Get the contents of a file
- `put`: Put contents into a file
- `append`: Append contents to a file
- `delete`: Delete a file
- `isDirectory`: Check if a path is a directory
- `makeDirectory`: Create a directory
- `deleteDirectory`: Delete a directory
- `readDirectory`: Read the contents of a directory
- `changeMode`: Change the mode of a file or directory
- `prepend`: Prepend contents to a file
- `link`: Create a symbolic link to a target file
- `name`: Get the file name without extension
- `baseName`: Get the base name of a file
- `dirName`: Get the directory name of a file
- `type`: Get the type of file
- `isReadable`: Check if a file is readable
- `isWriteable`: Check if a file is writeable
- `isFile`: Check if a path is a file
- `files`: Get all files in a directory
- `allFiles`: Get all files in a directory and its subdirectories
- `moveDirectory`: Move a directory to a new location
- `copyDirectory`: Copy a directory to a new location
- `cleanDirectories`: Delete all files in a directory
- `size`: Get the size of a file in bytes
- `lastModified`: Get the last modification time of a file as a UNIX
- `copy`: Copies a file from one location to another
- `move`: Moves a file from one location to another
- `extension`: Get extension of a file
- `mimeType`: Get the MIME type of file

Requirements
------------

[](#requirements)

- PHP 8.0 or Higher
- PHP File info Extension: `ext-fileinfo`

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

[](#installation)

First, include the File.php class in your project.

```
require_once 'path/to/File.php';
```

or by using composer `Recommended way`

```
composer require imran/file
```

Methods
-------

[](#methods)

### `exists`

[](#exists)

The `exists()` method checks if a file or directory exists.

```
$exists = File::exists('path/to/file');
```

### `get`

[](#get)

The `get()` method gets the contents of a file.

```
$contents = File::get('path/to/file');
```

### `put`

[](#put)

The `put()` method puts contents into a file.

```
File::put('path/to/file', 'contents');
```

### `append`

[](#append)

The `append()` method appends contents to a file.

```
File::append('path/to/file', 'contents');
```

### `delete`

[](#delete)

The `delete()` method deletes a file.

```
File::delete('path/to/file');
```

### `isDirectory`

[](#isdirectory)

The `isDirectory()` method checks if a path is a directory.

```
$isDirectory = File::isDirectory('path/to/directory');
```

### `makeDirectory`

[](#makedirectory)

The `makeDirectory()` method creates a directory.

```
File::makeDirectory('path/to/directory');
```

### `deleteDirectory`

[](#deletedirectory)

The `deleteDirectory()` method deletes a directory.

```
File::deleteDirectory('path/to/directory');
```

### `readDirectory`

[](#readdirectory)

The `readDirectory()` method reads the contents of a directory.

```
$contents = File::readDirectory('path/to/directory');
```

### `changeMode`

[](#changemode)

The `changeMode()` method changes the mode of a file or directory.

```
File::changeMode('path/to/file', 0777);
```

### `prepend`

[](#prepend)

The `prepend()` method prepends contents to a file.

```
File::prepend('path/to/file', 'contents');
```

### `move`

[](#move)

The `move()` method moves a file to a new location.

```
File::move('path/to/old/file', 'path/to/new/file');
```

### `link`

[](#link)

The `link()` method creates a symbolic link to a target file.

```
File::link('path/to/target', 'path/to/link');
```

### `name`

[](#name)

The `name()` method gets the file name without extension.

```
$name = File::name('path/to/file.ext');
```

### `basename`

[](#basename)

The `basename()` method gets the base name of a file.

```
$basename = File::basename('path/to/file.ext');
```

### `dirname`

[](#dirname)

The `dirname()` method gets the directory name of a file.

```
$dirname = File::dirname('path/to/file.ext');
```

### `type`

[](#type)

The `type()` method gets the type of file.

```
$type = File::type('path/to/file');
```

### `isReadable`

[](#isreadable)

The `isReadable()` method checks if a file is readable.

```
$isReadable = File::isReadable('path/to/file');
```

### `isWriteable`

[](#iswriteable)

The `isWriteable()` method checks if a file is writeable.

```
$isWriteable = File::isWriteable('path/to/file');
```

### `isFile`

[](#isfile)

The `isFile()` method checks if a path is a file.

```
$isFile = File::isFile('path/to/file');
```

### `files`

[](#files)

The `files()` method gets all files in a directory.

```
$files = File::files('path/to/directory');
```

### `allFiles`

[](#allfiles)

The `allFiles()` method gets all files in a directory and its subdirectories.

```
$allFiles = File::allFiles('path/to/directory');
```

### `moveDirectory`

[](#movedirectory)

The `moveDirectory()` method moves a directory to a new location.

```
File::moveDirectory('path/to/old/directory', 'path/to/new/directory');
```

### `copyDirectory`

[](#copydirectory)

The `copyDirectory()` method copies a directory to a new location.

```
File::copyDirectory('path/to/old/directory', 'path/to/new/directory');
```

### `cleanDirectory`

[](#cleandirectory)

The `cleanDirectory()` method deletes all files in a directory.

```
File::cleanDirectory('path/to/directory');
```

### `size`

[](#size)

The `size()` method returns the size of a file in bytes.

```
$size = File::size('path/to/file');
```

### `lastModified`

[](#lastmodified)

The `lastModified()` method returns the last modification time of a file as a UNIX timestamp.

```
$lastModified = File::lastModified('path/to/file');
```

### `copy`

[](#copy)

The `copy()` method copies a file from one location to another.

```
$source = 'path/to/source';
$destination = 'path/to/destination';

File::copy($source,destination);
```

### `move`

[](#move-1)

The `move()` method moves a file from one location to another.

```
$source = 'path/to/source';
$destination = 'path/to/destination';

File::move($source,destination);
```

### `extension`

[](#extension)

The `extension()` method returns the extension of a file.

```
$extension = File::extension('path/to/file');
```

### `mimeType`

[](#mimetype)

The `mimeType()` method returns the MIME type of file.

```
$mimeType = File::mimeType('path/to/file');
```

### Running Tests

[](#running-tests)

To run tests, use following command

```
.\vendor\bin\phpunit tests/FileTest.php
```

### Hi, I'm Imran Ali! 👋

[](#hi-im-imran-ali-)

### 🚀 About Me

[](#-about-me)

Senior **Full-Stack** Developer specializing in front end and back-end development. Experienced with all stages of the development cycle for dynamic web projects. Innovative, creative and a proven team player, I possess a Tech Degree in Front End Development and have 7 years building developing and managing websites, applications and programs for various companies. I seek to secure the position of Senior Full Stack Developer where i can share my skills, expertise and experience with valuable clients.

### 🛠 Skills

[](#-skills)

PHP OOP, Laravel, Codeigniter Javascript, Node, React, Vue, Git, HTML, Rest Api, Typescript, Angular, SCSS, Docker, CI/CD Jenkins, Bootstrap, Responsive Design, ASP.NET Core

### 🔗 Follow on

[](#-follow-on)

[![linkedin](https://camo.githubusercontent.com/9745a59ad4a919d2e524512c3f732c820d4aa0fe927def4f37c4aba08f7e42bc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c696e6b6564696e2d3041363643323f7374796c653d666f722d7468652d6261646765266c6f676f3d6c696e6b6564696e266c6f676f436f6c6f723d7768697465)](https://www.linkedin.com/in/imranali291/)[![twitter](https://camo.githubusercontent.com/79cbea7e1aa9ec614d34050bdc4128542d8527807ac8ce879f953ced3478375d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f747769747465722d3144413146323f7374796c653d666f722d7468652d6261646765266c6f676f3d74776974746572266c6f676f436f6c6f723d7768697465)](https://twitter.com/imranali125)

### License

[](#license)

[![MIT License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://choosealicense.com/licenses/mit/)[![GPLv3 License](https://camo.githubusercontent.com/da9c3abfd62c32a94031c3a382cb7c85dbd4cede411416837adfe6b8fda05ba1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c25323076332d79656c6c6f772e737667)](https://opensource.org/licenses/)[![AGPL License](https://camo.githubusercontent.com/aed477ac82de60abd644cfa7c9d381eebe9a00d5d32168644f7e6d2a23957d1b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4147504c2d626c75652e737667)](http://www.gnu.org/licenses/agpl-3.0)

### Contributing

[](#contributing)

Contributions are always welcome!

See `contributing.md` for ways to get started.

Please adhere to this project's `code of conduct`.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Unknown

Total

1

Last Release

1227d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7252105628ffa6f064585370161626c7c72e68dd2e74ee66aa50d5894543c183?d=identicon)[webz2feel](/maintainers/webz2feel)

---

Top Contributors

[![grim-reapper](https://avatars.githubusercontent.com/u/7957389?v=4)](https://github.com/grim-reapper "grim-reapper (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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