1. Go to this page and download the library: Download whikloj/bagittools 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/ */
whikloj / bagittools example snippets
use \whikloj\BagItTools\Bag;
$dir = "./newbag";
// Create new bag as directory $dir
$bag = Bag::create($dir);
// Add a file
$bag->addFile('../README.md', 'data/documentation/myreadme.md');
// Add another algorithm
$bag->addAlgorithm('sha1');
// Get the algorithms
$algos = $bag->getAlgorithms();
var_dump($algos); // array(
// 'sha512',
// 'sha1',
// )
// Add a fetch url
$bag->addFetchFile('http://www.google.ca', 'data/mywebsite.html');
// Add some bag-info tags
$bag->addBagInfoTag('Contact-Name', 'Jared Whiklo');
$bag->addBagInfoTag('CONTACT-NAME', 'Additional admins');
// Check for tags.
if ($bag->hasBagInfoTag('contact-name')) {
// Get tags
$tags = $bag->getBagInfoByTag('contact-name');
var_dump($tags); // array(
// 'Jared Whiklo',
// 'Additional admins',
// )
// Remove a specific tag value using array index from the above listing.
$bag->removeBagInfoTagIndex('contact-name', 1);
// Get tags
$tags = $bag->getBagInfoByTag('contact-name');
var_dump($tags); // array(
// 'Jared Whiklo',
// )
$bag->addBagInfoTag('Contact-NAME', 'Bob Saget');
// Get tags
$tags = $bag->getBagInfoByTag('contact-name');
var_dump($tags); // array(
// 'Jared Whiklo',
// 'Bob Saget',
// )
// Without the case sensitive flag as true, you must be exact.
$bag->removeBagInfoTagValue('contact-name', 'bob saget');
$tags = $bag->getBagInfoByTag('contact-name');
var_dump($tags); // array(
// 'Jared Whiklo',
// 'Bob Saget',
// )
// With the case sensitive flag set to false, you can be less careful
$bag->removeBagInfoTagValue('contact-name', 'bob saget', false);
$tags = $bag->getBagInfoByTag('contact-name');
var_dump($tags); // array(
// 'Jared Whiklo',
// )
// Remove all values for the specified tag.
$bag->removeBagInfoTag('contact-name');
}
// Write the bag to the specified path and filename using the expected archiving method.
$bag->package('./archive.tar.bz2');
use \whikloj\BagItTools\Bag;
$dir = "./newbag";
// Create new bag as directory $dir
$bag = Bag::create($dir);
// Add a profile by URL
$bag->addBagProfileByURL("https://some.example.com/bagit-profile.json");
// or add a profile by JSON
$bag->addBagProfileByJson(file_get_contents("path/to/bagit-profile.json"));
// Add a file
$bag->addFile('../README.md', 'data/documentation/myreadme.md');
// Add another algorithm
$bag->addAlgorithm('sha1');
// Write the bag to the specified path and filename using the expected archiving method.
$bag->package('./archive.tar.bz2');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.