Skip to content

Instantly share code, notes, and snippets.

@nagiyevelchin
Last active October 7, 2023 11:31
Show Gist options
  • Save nagiyevelchin/5660cc8b50146bbb272c23f96e1fdc41 to your computer and use it in GitHub Desktop.
Save nagiyevelchin/5660cc8b50146bbb272c23f96e1fdc41 to your computer and use it in GitHub Desktop.
This PHP code is designed to handle zip file extraction - unzip based on a 'zip' parameter provided through a GET request.
<?php
// Check if the 'zip' parameter is empty in the GET request.
if(empty($_GET['zip'])){
// If 'zip' parameter is empty, terminate the script and display 'No zip!' message.
die('No zip!');
}
// Create a new instance of the ZipArchive class.
$zip = new ZipArchive;
// Try to open the zip file specified in the 'zip' parameter.
$res = $zip->open($_GET['zip']);
// Check if the zip file was successfully opened.
if ($res === TRUE) {
// If the zip file was opened successfully, extract its contents to the current directory.
$zip->extractTo('./');
// Close the zip file.
$zip->close();
// Display 'Ok' to indicate successful extraction.
echo 'Ok';
} else {
// If the zip file couldn't be opened, display 'Not ok' to indicate an error.
echo 'Not ok';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment