PHPackages                             vakata/downloader - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. vakata/downloader

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vakata/downloader
=================

A PHP class for making a static copy (or indexing) a site

1.0.3(1y ago)0728MITPHPPHP &gt;=8.0.0

Since Feb 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/vakata/downloader)[ Packagist](https://packagist.org/packages/vakata/downloader)[ Docs](https://github.com/vakata/downloader)[ RSS](/packages/vakata-downloader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

downloader
==========

[](#downloader)

A PHP class for making a static copy (or indexing) a site

Usage
-----

[](#usage)

```
// download a whole site to a folder
(new Downloader('https://domain.tld/'))->download(__DIR__ . '/domain.tld/');

// download a part of site to a folder
(new Downloader('https://domain.tld/some-path/'))->download(__DIR__ . '/my-backup-copy/');

// if you want to host the static copy out of a subfolder - specify the webroot prefix
(new Downloader('https://domain.tld/'))->download(__DIR__ . '/static/', 'static');

// it is possible to specify a custom downloader
(new Downloader(
    'https://domain.tld/',
    function (string $url): string {
        // fetch the $url and return the contents as you see fit
    }
))->download(__DIR__ . '/static/');

// you can invoke a callback for each item and if that callback returns false - omit writing to disk
// this is useful for indexing purposes
(new Downloader(
    'https://domain.tld/',
    null,
    function (string $url, string $data) {
        // EXAMPLE: save to a database for indexing
        return false;
    }
))->download(__DIR__ . '/static/');
```

Helpers
-------

[](#helpers)

```
// there are a couple of methods to help with copying and removing dirs
public static function emptyDir(string $dir, bool $delete_self = false): void;
public static function copyDir(string $src, string $dst): void;
```

Example shell script
--------------------

[](#example-shell-script)

Used as:

```
./downloader.php "https://some.tld/"
```

```
#!/usr/bin/env php
