Recommend this page to a friend! |
Download .zip |
Info | Example | View files (5) | Download .zip | Reputation | Support forum (5) | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2020-09-05 (14 hours ago) | 59% | Total: 745 This week: 2 | All time: 4,441 This week: 143 |
Version | License | PHP version | Categories | |||
rar-archiver 1.0.3 | BSD License | 5.5.11 | PHP 5, Files and Folders, Compression |
Description | Author | |||
This class can create, manipulate and extract RAR archives. Innovation Award
|
Class for working with archives RAR. It allows you to add files to the directory, as well as extract, delete, rename, and get content.
1) Install composer
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';
void RarArchiver::__construct ( string $file [, $flag = 0] )
It creates or opens a file and initializes it.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
boolean RarArchiver::isRar ( void )
Checks whether the file archive RAR.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->isRar()) {
echo 'ok';
} else {
echo 'failed';
}
array RarArchiver::getFileList ( void )
Gets a list of files in the archive.
Returns the filled array on success, or an empty array on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if (count($rar->getFileList()) > 0) {
echo 'ok';
} else {
echo 'failed';
}
boolean RarArchiver::addEmptyDir ( string $dirname )
Adds an empty directory in the archive.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->addEmptyDir('newEmptyDirectory')) {
echo 'Created a new root directory';
} else {
echo 'Could not create the directory';
}
boolean RarArchiver::addFile ( string $filename [, string $localname = ''] )
Adds a file to a RAR archive from a given path.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->addFile('/path/to/index.txt', 'newname.txt')) {
echo 'ok';
} else {
echo 'failed';
}
boolean RarArchiver::addFromString ( string $localname , string $contents )
Add a file to a RAR archive using its contents.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->addFromString('newname.txt', 'file content goes here')) {
echo 'ok';
} else {
echo 'failed';
}
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.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
$rar->buildFromDirectory(dirname(__FILE__) . '/project');
// or
$rar->buildFromDirectory(dirname(__FILE__) . '/project', '/\.php$/');
boolean RarArchiver::deleteIndex ( int $index )
Delete an entry in the archive using its index.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->deleteIndex(2)) {
echo 'ok';
} else {
echo 'failed';
}
boolean RarArchiver::deleteName ( string $name )
Delete an entry in the archive using its name.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->deleteName('testfromfile.php')) {
echo 'ok';
} else {
echo 'failed';
}
string RarArchiver::getFromIndex ( int $index [, int $length = 0] )
Returns the entry contents using its index.
Returns the contents of the entry on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
$rar->getFromIndex(2);
// or
$rar->getFromIndex(2, 100);
string RarArchiver::getFromName ( string $name [, int $length = 0] )
Returns the entry contents using its name.
Returns the contents of the entry on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
$rar->getFromName('testfromfile.php');
// or
$rar->getFromIndex('testfromfile.php', 100);
string RarArchiver::getNameIndex ( int $index )
Returns the name of an entry using its index.
Returns the name on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
$rar->getNameIndex(2);
boolean RarArchiver::renameIndex ( int $index , string $newname )
Renames an entry defined by its index.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->renameIndex(2, 'newname.php')) {
echo 'ok';
} else {
echo 'failed';
}
boolean RarArchiver::renameName ( string $name , string $newname )
Renames an entry defined by its name.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->renameName('testfromfile.php', 'newname.php')) {
echo 'ok';
} else {
echo 'failed';
}
boolean RarArchiver::extractTo ( string $destination [, mixed $entries ] )
Extract the complete archive or the given files to the specified destination.
Returns TRUE on success or FALSE on failure.
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->extractTo('/my/destination/dir/')) {
echo 'ok';
} else {
echo 'failed';
}
Files |
File | Role | Description |
---|---|---|
composer.json | Data | Auxiliary data |
example.php | Example | Example script |
LICENSE | Lic. | License text |
RarArchiver.php | Class | Class source |
README.md | Doc. | Documentation |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
User Ratings | ||||||||||||||||||||||||||||||
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.