PHPackages                             dirpag/dirpag - 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. [Search &amp; Filtering](/categories/search)
4. /
5. dirpag/dirpag

ActiveLibrary[Search &amp; Filtering](/categories/search)

dirpag/dirpag
=============

Search and Paginate Directory Content.

v0.2(3y ago)19MITPHPPHP &gt;=5.4.0

Since Mar 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/phrenotype/DirPag)[ Packagist](https://packagist.org/packages/dirpag/dirpag)[ RSS](/packages/dirpag-dirpag/feed)WikiDiscussions main Synced yesterday

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

DirPag (Directory Paginator)
============================

[](#dirpag-directory-paginator)

Let's say you want to build a web-based file manager, some folders may have thousands of files. Displaying all of them on a single page will slow down page load time. In fact, keeping all the files in memory alone might crash some servers. With this library, you can paginate the directory content, perform your operations, and get faster page load.

This is a small library that helps you search and paginate results of directory content.

Install
-------

[](#install)

```
composer require dirpag/dirpag
```

Usage
-----

[](#usage)

There are two use cases.

1. You have a directory you would like to paginate its contents.
2. You want to search for a file or folder in a directory and get the results (max depth of 1)

Before delving into each of the above, it is vital we look at the `DirPag\Result` object, which I will refer to as the `result object` from now on.

The result object contains three important pieces of information which are accessed via the following methods.

1. `->values()` : This is an array of the paged content.
2. `->last_page()` : This is the last page. This is important if you wish to display pages to the user to pick.
3. `->total_count()` : This is the total number of items in the iterable or directory.

The examples and explanations below will clear things up. Just remember that all the three major operations return a `result object`.

### PAGINATING DIRECTORY CONTENT

[](#paginating-directory-content)

Here, the `DirPag\DirPag::page($path, $page_number)` static method is used.

```
