PHPackages                             dmamontov/rararchiver - 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. dmamontov/rararchiver

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

dmamontov/rararchiver
=====================

Class for working with archives RAR.

1.0.0(11y ago)3111.1k10[1 PRs](https://github.com/dmamontov/rararchiver/pulls)BSD-3-ClausePHPPHP &gt;=5.5.11

Since May 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/dmamontov/rararchiver)[ Packagist](https://packagist.org/packages/dmamontov/rararchiver)[ Docs](http://www.slobel.ru/)[ RSS](/packages/dmamontov-rararchiver/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/7613af92d4d04d72fb46ebd251b68df2f905c3fe0f83e58a2359c96d68522098/68747470733a2f2f706f7365722e707567782e6f72672f646d616d6f6e746f762f72617261726368697665722f762f737461626c652e737667)](https://packagist.org/packages/dmamontov/rararchiver)[![License](https://camo.githubusercontent.com/aab2d09566dd73f36a97b7b71b8f2ffe531eca555e93d78d4197d58651ff5ea5/68747470733a2f2f706f7365722e707567782e6f72672f646d616d6f6e746f762f72617261726368697665722f6c6963656e73652e737667)](https://packagist.org/packages/dmamontov/rararchiver)

In the process version 2.0.
===========================

[](#in-the-process-version-20)

RarArchiver
===========

[](#rararchiver)

Class for working with archives RAR. It allows you to add files to the directory, as well as extract, delete, rename, and get content.

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

[](#requirements)

- PHP version ~5.5.11

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

[](#installation)

1. Install [composer](https://getcomposer.org/download/)
2. Follow in the project folder:

```
composer require dmamontov/rararchiver ~1.0.0
```

In config `composer.json` your project will be added to the library `dmamontov/rararchiver`, who settled in the folder `vendor/`. In the absence of a config file or folder with vendors they will be created.

If before your project is not used `composer`, connect the startup file vendors. To do this, enter the code in the project:

```
require 'path/to/vendor/autoload.php';
```

Available methods
-----------------

[](#available-methods)

### RarArchiver::\_\_construct

[](#rararchiver__construct)

#### Description

[](#description)

```
void RarArchiver::__construct ( string $file [, $flag = 0] )
```

It creates or opens a file and initializes it.

#### Parameters

[](#parameters)

- `file` - The path to archive.
- `flag` - An optional parameter.
- `RarArchiver::CREATE` - It creates the archive if it is not found.
- `RarArchiver::REPLACE` - Overwrites the archive if it is found, otherwise create it.

#### Examples

[](#examples)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
```

### RarArchiver::isRar

[](#rararchiverisrar)

#### Description

[](#description-1)

```
boolean RarArchiver::isRar ( void )
```

Checks whether the file archive RAR.

#### Return Values

[](#return-values)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-1)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->isRar()) {
    echo 'ok';
} else {
	echo 'failed';
}
```

### RarArchiver::getFileList

[](#rararchivergetfilelist)

#### Description

[](#description-2)

```
array RarArchiver::getFileList ( void )
```

Gets a list of files in the archive.

#### Return Values

[](#return-values-1)

Returns the filled array on success, or an empty array on failure.

#### Examples

[](#examples-2)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if (count($rar->getFileList()) > 0) {
    echo 'ok';
} else {
	echo 'failed';
}
```

### RarArchiver::addEmptyDir

[](#rararchiveraddemptydir)

#### Description

[](#description-3)

```
boolean RarArchiver::addEmptyDir ( string $dirname )
```

Adds an empty directory in the archive.

#### Parameters

[](#parameters-1)

- `dirname` - The directory to add.

#### Return Values

[](#return-values-2)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-3)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->addEmptyDir('newEmptyDirectory')) {
    echo 'Created a new root directory';
} else {
	echo 'Could not create the directory';
}
```

### RarArchiver::addFile

[](#rararchiveraddfile)

#### Description

[](#description-4)

```
boolean RarArchiver::addFile ( string $filename [, string $localname = ''] )
```

Adds a file to a RAR archive from a given path.

#### Parameters

[](#parameters-2)

- `filename` - The path to the file to add.
- `localname` - If supplied, this is the local name inside the RAR archive that will override the `filename`.

#### Return Values

[](#return-values-3)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-4)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->addFile('/path/to/index.txt', 'newname.txt')) {
    echo 'ok';
} else {
	echo 'failed';
}
```

### RarArchiver::addFromString

[](#rararchiveraddfromstring)

#### Description

[](#description-5)

```
boolean RarArchiver::addFromString ( string $localname , string $contents )
```

Add a file to a RAR archive using its contents.

#### Parameters

[](#parameters-3)

- `localname` - The name of the entry to create.
- `contents` - The contents to use to create the entry.

#### Return Values

[](#return-values-4)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-5)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->addFromString('newname.txt', 'file content goes here')) {
    echo 'ok';
} else {
	echo 'failed';
}
```

### RarArchiver::buildFromDirectory

[](#rararchiverbuildfromdirectory)

#### Description

[](#description-6)

```
void RarArchiver::buildFromDirectory ( string $path [, string $regex ] )
```

Populate a RAR archive from directory contents. The optional second parameter is a regular expression (pcre) that is used to exclude files.

#### Parameters

[](#parameters-4)

- `path` - The full or relative path to the directory that contains all files to add to the archive.
- `regex` - An optional pcre regular expression that is used to filter the list of files. Only file paths matching the regular expression will be included in the archive.

#### Examples

[](#examples-6)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

$rar->buildFromDirectory(dirname(__FILE__) . '/project');
// or
$rar->buildFromDirectory(dirname(__FILE__) . '/project', '/\.php$/');
```

### RarArchiver::deleteIndex

[](#rararchiverdeleteindex)

#### Description

[](#description-7)

```
boolean RarArchiver::deleteIndex ( int $index )
```

Delete an entry in the archive using its index.

#### Parameters

[](#parameters-5)

- `index` - Index of the entry to delete.

#### Return Values

[](#return-values-5)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-7)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->deleteIndex(2)) {
    echo 'ok';
} else {
	echo 'failed';
}
```

### RarArchiver::deleteName

[](#rararchiverdeletename)

#### Description

[](#description-8)

```
boolean RarArchiver::deleteName ( string $name )
```

Delete an entry in the archive using its name.

#### Parameters

[](#parameters-6)

- `name` - Name of the entry to delete.

#### Return Values

[](#return-values-6)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-8)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->deleteName('testfromfile.php')) {
    echo 'ok';
} else {
	echo 'failed';
}
```

### RarArchiver::getFromIndex

[](#rararchivergetfromindex)

#### Description

[](#description-9)

```
string RarArchiver::getFromIndex ( int $index [, int $length = 0] )
```

Returns the entry contents using its index.

#### Parameters

[](#parameters-7)

- `index` - Index of the entry.
- `length` - The length to be read from the entry. If 0, then the entire entry is read.

#### Return Values

[](#return-values-7)

Returns the contents of the entry on success or FALSE on failure.

#### Examples

[](#examples-9)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

$rar->getFromIndex(2);
// or
$rar->getFromIndex(2, 100);
```

### RarArchiver::getFromName

[](#rararchivergetfromname)

#### Description

[](#description-10)

```
string RarArchiver::getFromName ( string $name [, int $length = 0] )
```

Returns the entry contents using its name.

#### Parameters

[](#parameters-8)

- `name` - Name of the entry.
- `length` - The length to be read from the entry. If 0, then the entire entry is read.

#### Return Values

[](#return-values-8)

Returns the contents of the entry on success or FALSE on failure.

#### Examples

[](#examples-10)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

$rar->getFromName('testfromfile.php');
// or
$rar->getFromIndex('testfromfile.php', 100);
```

### RarArchiver::getNameIndex

[](#rararchivergetnameindex)

#### Description

[](#description-11)

```
string RarArchiver::getNameIndex ( int $index )
```

Returns the name of an entry using its index.

#### Parameters

[](#parameters-9)

- `index` - Index of the entry.

#### Return Values

[](#return-values-9)

Returns the name on success or FALSE on failure.

#### Examples

[](#examples-11)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

$rar->getNameIndex(2);
```

### RarArchiver::renameIndex

[](#rararchiverrenameindex)

#### Description

[](#description-12)

```
boolean RarArchiver::renameIndex ( int $index , string $newname )
```

Renames an entry defined by its index.

#### Parameters

[](#parameters-10)

- `index` - Index of the entry to rename.
- `newname` - New name.

#### Return Values

[](#return-values-10)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-12)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->renameIndex(2, 'newname.php')) {
    echo 'ok';
} else {
	echo 'failed';
}
```

### RarArchiver::renameName

[](#rararchiverrenamename)

#### Description

[](#description-13)

```
boolean RarArchiver::renameName ( string $name , string $newname )
```

Renames an entry defined by its name.

#### Parameters

[](#parameters-11)

- `name` - Name of the entry to rename.
- `newname` - New name.

#### Return Values

[](#return-values-11)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-13)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->renameName('testfromfile.php', 'newname.php')) {
    echo 'ok';
} else {
	echo 'failed';
}
```

### RarArchiver::extractTo

[](#rararchiverextractto)

#### Description

[](#description-14)

```
boolean RarArchiver::extractTo ( string $destination [, mixed $entries ] )
```

Extract the complete archive or the given files to the specified destination.

#### Parameters

[](#parameters-12)

- `destination` - Location where to extract the files.
- `entries` - The entries to extract. It accepts either a single entry name or an array of names.

#### Return Values

[](#return-values-12)

Returns TRUE on success or FALSE on failure.

#### Examples

[](#examples-14)

```
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);

if ($rar->extractTo('/my/destination/dir/')) {
    echo 'ok';
} else {
	echo 'failed';
}
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

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

4054d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5955726?v=4)[Dmitry Mamontov](/maintainers/dmamontov)[@dmamontov](https://github.com/dmamontov)

---

Top Contributors

[![dmamontov](https://avatars.githubusercontent.com/u/5955726?v=4)](https://github.com/dmamontov "dmamontov (5 commits)")

---

Tags

rararchivesarchiverwinrar

### Embed Badge

![Health badge](/badges/dmamontov-rararchiver/health.svg)

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

###  Alternatives

[mmoreram/extractor

Extractor project for php

21134.2k8](/packages/mmoreram-extractor)

PHPackages © 2026

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