How can a zip file be uploaded and then unpacked on a server using PHP?
To upload and unpack a zip file on a server using PHP, you can first handle the file upload using a form with enctype set to "multipart/form-data". Once the file is uploaded, you can use the ZipArchive class in PHP to extract the contents of the zip file.
<?php
if(isset($_FILES['zip_file'])){
$zip = new ZipArchive;
$zip_file = $_FILES['zip_file']['tmp_name'];
$zip->open($zip_file);
$zip->extractTo('path/to/extracted/files/');
$zip->close();
echo 'Zip file uploaded and unpacked successfully.';
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="zip_file">
<input type="submit" value="Upload and Unpack">
</form>