PHP code example of dmamontov / rararchiver
1. Go to this page and download the library: Download dmamontov/rararchiver library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dmamontov / rararchiver example snippets
void RarArchiver::__construct ( string $file [, $flag = 0] )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
boolean RarArchiver::isRar ( void )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->isRar()) {
echo 'ok';
} else {
echo 'failed';
}
array RarArchiver::getFileList ( void )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if (count($rar->getFileList()) > 0) {
echo 'ok';
} else {
echo 'failed';
}
boolean RarArchiver::addEmptyDir ( string $dirname )
$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 = ''] )
$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 )
$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 ] )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
$rar->buildFromDirectory(dirname(__FILE__) . '/project');
// or
$rar->buildFromDirectory(dirname(__FILE__) . '/project', '/\.php$/');
boolean RarArchiver::deleteIndex ( int $index )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->deleteIndex(2)) {
echo 'ok';
} else {
echo 'failed';
}
boolean RarArchiver::deleteName ( string $name )
$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] )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
$rar->getFromIndex(2);
// or
$rar->getFromIndex(2, 100);
string RarArchiver::getFromName ( string $name [, int $length = 0] )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
$rar->getFromName('testfromfile.php');
// or
$rar->getFromIndex('testfromfile.php', 100);
string RarArchiver::getNameIndex ( int $index )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
$rar->getNameIndex(2);
boolean RarArchiver::renameIndex ( int $index , string $newname )
$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 )
$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 ] )
$rar = new RarArchiver('example.rar', RarArchiver::CREATE);
if ($rar->extractTo('/my/destination/dir/')) {
echo 'ok';
} else {
echo 'failed';
}