Last Updated: January 15, 2026
a step-by-step tutorial for creating a simple file unzipper using PHP and Bootstrap:
Step 1: Setting up the HTML Structure
Initially, we should come up with the basic elements of our web page–a form which is able to have a selection option to choose the archive file and a button for submitting the values, which is what the page is going to be built with.
<!DOCTYPE html>
<html>
<head>
<title>Extract Archive</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container mt-5">
<h2>Extract Archive</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<div class="form-group">
<label for="archive_file">Select Archive File:</label>
<select class="form-control" id="archive_file" name="archive_file">
<!-- Archive file options will be added here -->
</select>
</div>
<button type="submit" class="btn btn-primary">Extract Archive</button>
</form>
</div>
</body>
</html>How to Make a Beautiful Shoutcast Radio Player
As a first and the foremost step, we have introduced the crucial HTML tags, have linked the Bootstrap CSS and JavaScript files further we have created a container div with a heading and a form.
Step 2: Populating the Select Option with Archive Files
After this, we will employ PHP to obtain all archive files (ZIP, RAR, GZ, TAR.GZ, and TAR) from the main directory and then list them as options on select element.
<select class="form-control" id="archive_file" name="archive_file">
<?php
// Get all archive files (zip, rar, gz, tar.gz, tar) in the root directory
$archive_files = array_merge(
glob("*.zip"),
glob("*.rar"),
glob("*.gz"),
glob("*.tar.gz"),
glob("*.tar")
);
// Loop through archive files and add them as options
foreach ($archive_files as $file) {
echo "<option value='$file'>$file</option>";
}
?>
</select>At this point, we are dealing with PHP’s glob function which allows us to gather the files of the specified formats (ZIP, RAR, GZ, TAR.GZ, and TAR) from the directory partly. These files can be then included as choices in the select element by the echo statement with the help of the loop.
Step 3: Processing the Form Submission
Next, we’ll upload the PHP code to address the form submission and extract the chosen archive record.
<?php
// Check if the form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the selected archive file
$archiveFile = $_POST["archive_file"];
// Get the archive file extension
$fileExt = pathinfo($archiveFile, PATHINFO_EXTENSION);
// Create a directory with the same name as the archive file
$targetDir = basename($archiveFile, "." . $fileExt);
if (!is_dir($targetDir)) {
mkdir($targetDir);
}
// Extract the archive file
if ($fileExt == "zip") {
$zip = new ZipArchive();
if ($zip->open($archiveFile) === TRUE) {
$zip->extractTo($targetDir);
$zip->close();
}
} elseif ($fileExt == "rar") {
$rar = RarArchive::open($archiveFile);
$entries = $rar->getEntries();
foreach ($entries as $entry) {
$entry->extract($targetDir);
}
$rar->close();
} elseif ($fileExt == "gz" || $fileExt == "tar.gz" || $fileExt == "tar") {
$phar = new PharData($archiveFile);
$phar->extractTo($targetDir);
}
}
?>
In this step, we first test if the form became submitted using the $_SERVER[“REQUEST_METHOD”] variable. If the shape changed into submitted, we retrieve the selected archive record from the form information the use of $_POST[“archive_file”].
Next, we use the pathinfo function to get the file extension of the selected archive report, which helps us decide the proper extraction technique.
Before extracting the archive, we create a brand new directory with the same name as the archive file (with out the extension) the usage of the mkdir characteristic.
Depending on the archive document extension, we use one-of-a-kind lessons and methods to extract the archive:
For ZIP documents, we use the ZipArchive magnificence.
For RAR files, we use the RarArchive elegance from the rar extension.
For GZ, TAR.GZ, and TAR files, we use the PharData elegance.
Note: This code assumes that the server has the important permissions to examine and write files within the root listing and create new directories. Additionally, make certain to replace the Bootstrap CSS and JavaScript links with the appropriate paths if you have the documents domestically or modify the code therefore in case you opt to use a one of a kind CSS framework or library.
In the next step, we’re going to talk the way to enlarge and customize this code to suit your specific necessities, consisting of adding errors managing, enter validation, or additional capability like document deletion or compression.
This code will scan all Archive file of folder or root where it uploaded and with this unzipper you can unzip any Archive file( This code wouldn’t unzip password locked file)

