PHP code example of indy2kro / php-iso

1. Go to this page and download the library: Download indy2kro/php-iso 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/ */

    

indy2kro / php-iso example snippets




use PhpIso\IsoFile;

$isoFile = new IsoFile('test.iso');
$volume = $isoFile->getPreferredVolume();

foreach ($volume->walk($isoFile) as $entry) {
    echo $entry->path, $entry->isDirectory ? '/' : ' (' . $entry->size . ' bytes)', PHP_EOL;
}

$fileSystem = $isoFile->getFileSystem();   // ?FileSystem

$entry = $fileSystem->find($isoFile, '/dir/readme.txt');

if ($entry !== null) {
    $content = $fileSystem->readFile($isoFile, $entry);      // whole file, limited by IsoFile::MAX_READ_LENGTH

    $stream = $fileSystem->openStream($isoFile, $entry);     // seekable stream, read from the image on demand
    echo fread($stream, 100);
    fclose($stream);
}

foreach ($fileSystem->search($isoFile, '*.txt') as $match) {
    echo $match->path, PHP_EOL;
}

echo $entry->mode, $entry->uid, $entry->gid;   // null when the image has no such information
echo $entry->getSymlinkTarget();               // null unless the entry is a symbolic link

$isoFile = IsoFile::fromStream(STDIN);
$isoFile = IsoFile::fromStream($stream, 512 * 1024 * 1024); // custom limit in bytes

(new \PhpIso\Extractor())->extract($isoFile, $fileSystem, '/tmp/out');

// keep the Rock Ridge permissions and carry on after an unsafe name or a failed write
$extractor = new \PhpIso\Extractor(preserveMode: true, continueOnError: true);
$extractor->extract($isoFile, $fileSystem, '/tmp/out');
print_r($extractor->getErrors());   // entry path => message

$catalog = $isoFile->getBootRecord()?->loadCatalog($isoFile);
$entry = $catalog?->getDefaultEntry();
echo $entry?->getMediaName(), PHP_EOL;
$catalog?->extractImage($isoFile, $entry, 'boot.img');

$warnings = new \PhpIso\WalkWarnings();
foreach ($volume->walk($isoFile, 64, $warnings) as $entry) {
    // ...
}
foreach ($warnings->all() as $warning) {
    echo 'WARNING: ' . $warning . PHP_EOL;
}



use PhpIso\IsoFile;
use PhpIso\Descriptor\Type;
use PhpIso\Descriptor\PrimaryVolume;
use PhpIso\FileDirectory;
use PhpIso\PathTableRecord;

$isoFilePath = 'test.iso';

$isoFile = new IsoFile($isoFilePath);

// you can process each descriptor using $isoFile->descriptors directly

/** @var PrimaryVolume $primaryVolumeDescriptor */
$primaryVolumeDescriptor = $isoFile->descriptors[Type::PRIMARY_VOLUME_DESC];

// get the path table
$pathTable = $primaryVolumeDescriptor->loadTable($isoFile);

$paths = [];

/** @var PathTableRecord $pathRecord */
foreach ($pathTable as $pathRecord) {
    $currentPath = $pathRecord->getFullPath($pathTable);

    $paths[$currentPath] = [];

    // check extents
    $extents = $pathRecord->loadExtents($isoFile, $primaryVolumeDescriptor->blockSize);

    if ($extents !== false) {
        /** @var FileDirectory $extentRecord */
        foreach ($extents as $extentRecord) {
            $path = $extentRecord->fileId;
            if ($extentRecord->isDirectory()) {
                $path .= '/';
            }
            $paths[$currentPath][] = $path;
        }
    }
}

print_r($paths);