PHP
Chilkat2 PHP
Create Self-Extracting Executable (Windows-only)
Demonstrates how to create a Windows self-extracting EXE.Chilkat PHP Downloads
<?php
use Chilkat2\Zip;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$zip = new Zip();
// Called periodically while a method runs (every HeartbeatMs milliseconds).
$zip->onAbortCheck(function (): bool {
return false; // return true to abort the method in progress
});
$zip->onPercentDone(function (int $percentDone): bool {
echo 'Percent Done: ', $percentDone, "\n";
// Explicitly abort at 25% or greater.
// Remove this to allow for the HTTP download to run to completion.
if ($percentDone > 25) {
return true; // abort the method in progress
}
return false; // return true to abort the method in progress
});
$zip->onProgressInfo(function (string $name, string $value): void {
echo $name, ': ', $value, "\n";
});
// Initialize the zip object. Because we're creating
// a self-extracting EXE in this example, the filename
// passed to NewZip will never actually be created.
try {
$zip->NewZip('notUsed.zip');
// Append a directory tree. The AppendFiles does
// not read the file contents or append them to the zip
// object in memory. It simply appends references
// to the files so that when WriteExe (or WriteZipAndClose,
// or WriteZip, etc.) is called, the files are compressed
// and added to the archive.
$recurse = true;
$zip->AppendFiles('c:/temp/a/*', $recurse);
// Write "sfx.exe"
$zip->WriteExe('c:/temp/sfx.exe');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}