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

AbandonedLibrary

popphp/pop-file
===============

Pop File Component for Pop PHP Framework

2.1.0p1(9y ago)2948New BSDPHPPHP &gt;=5.4.0

Since Jul 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/popphp/pop-file)[ Packagist](https://packagist.org/packages/popphp/pop-file)[ Docs](http://www.popphp.org/)[ RSS](/packages/popphp-pop-file/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

pop-file
========

[](#pop-file)

END OF LIFE
-----------

[](#end-of-life)

The `pop-file` component v2.1.0 is now end-of-life. The upload and dir sub-components have been forked and pushed into other repositories, respectively:

- popphp/pop-http (now the Pop\\Http\\Upload class)
- popphp/pop-dir (now the Pop\\Dir\\Dir class)

[![Build Status](https://camo.githubusercontent.com/b296b21dac766b2970431fe16c10c7b247c9558b362f2050a6f3fda1386c1cbd/68747470733a2f2f7472617669732d63692e6f72672f706f707068702f706f702d66696c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/popphp/pop-file)[![Coverage Status](https://camo.githubusercontent.com/a3d4266d23e8b0ed235744032ba3745da37f04a1cfadb7aa48e85c07351a35d8/687474703a2f2f63632e706f707068702e6f72672f636f7665726167652e7068703f636f6d703d706f702d66696c65)](http://cc.popphp.org/pop-file/)

OVERVIEW
--------

[](#overview)

`pop-file` is a component for managing file uploads and easily traversing files within a directory. With file uploads, you can set fine-grain controls to manage specific upload parameters like file types and file size. Also, you can traverse directories recursively as well.

`pop-file`is a component of the [Pop PHP Framework](http://www.popphp.org/).

INSTALL
-------

[](#install)

Install `pop-file` using Composer.

```
composer require popphp/pop-file

```

BASIC USAGE
-----------

[](#basic-usage)

### File uploads

[](#file-uploads)

##### Basic file upload

[](#basic-file-upload)

```
use Pop\File\Upload;

$upload = new Upload('/path/to/uploads');
$upload->useDefaults();

$upload->upload($_FILES['file_upload']);

// Do something with the newly uploaded file
if ($upload->isSuccess()) {
    $file = $upload->getUploadedFile();
} else {
    echo $upload->getErrorMessage();
}
```

The above code creates the upload object, sets the upload path and sets the basic defaults, which includes a max file size of 10MBs, and an array of allowed common file types as well as an array of common disallowed file types.

##### File upload names and overwrites

[](#file-upload-names-and-overwrites)

By default, the file upload object will not overwrite a file of the same name. In the above example, if `$_FILES['file_upload']['name']` is set to 'my\_document.docx' and that file already exists in the upload path, it will be renamed to 'my\_document\_1.docx'.

If you want to enable file overwrites, you can simply do this:

```
$upload->overwrite(true);
```

Also, you can give the file a direct name on upload like this:

```
$upload->upload($_FILES['file_upload'], 'my-custom-filename.docx');
```

And if you need to check for a duplicate filename first, you can use the `checkFilename`method. If the filename exists, it will append a '\_1' to the end of the filename, or loop through until it finds a number that doesn't exist yet (\_#). If the filename doesn't exist yet, it returns the original name.

```
$filename = $upload->checkFilename('my-custom-filename.docx');

// $filename is set to 'my-custom-filename_1.docx'
$upload->upload($_FILES['file_upload'], $filename);
```

### Directory traversal

[](#directory-traversal)

##### Traversing a directory

[](#traversing-a-directory)

```
use Pop\File\Dir;

$dir = new Dir('my-dir');

foreach ($dir->getFiles() as $file) {
    echo $file;
}
```

If you want to traverse the directory recursively and get the full path of each file.

```
use Pop\File\Dir;

$dir = new Dir('my-dir', [
    'absolute'  => true,
    'recursive' => true
]);

foreach ($dir->getFiles() as $file) {
    echo $file;
}
```

The available boolean options for the `$options` array parameter are:

- 'absolute' =&gt; store the absolute, full path of the items in the directory
- 'relative' =&gt; store the relative path of the items in the directory
- 'recursive' =&gt; traverse the directory recursively
- 'filesOnly' =&gt; store only files in the object (and not other directories)

##### Emptying a directory

[](#emptying-a-directory)

```
use Pop\File\Dir;

$dir = new Dir('my-dir');
$dir->emptyDir(true);
```

The `true` flag will remove the actually directory as well.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~109 days

Total

7

Last Release

3358d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c19dee900e9e20039c723cc403f76b5c22ac2dddb3f86773ae64fb082d4949e2?d=identicon)[nicksagona](/maintainers/nicksagona)

---

Top Contributors

[![nicksagona](https://avatars.githubusercontent.com/u/898670?v=4)](https://github.com/nicksagona "nicksagona (28 commits)")

---

Tags

phpdirectoryfile uploadspoppop phpdirectory traversing

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[popphp/pop-http

Pop Http Component for Pop PHP Framework

1018.5k13](/packages/popphp-pop-http)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1814.6k11](/packages/popphp-pop-db)[popphp/pop-pdf

PHP PDF library for generating and importing PDF documents. A component of the Pop PHP Framework

207.8k1](/packages/popphp-pop-pdf)

PHPackages © 2026

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