Av@Tech
Learner
How can i make a folder compress into a ZIP file as a download?
How can i make a folder compress into a ZIP file as a download?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
You can use ZipArchive class to zipping and unzipping a folder. It might be need to install the class if it is not present in the server.
Example:
<?php
// Enter the name of foldee
$pathdir
=
"Folder Name/"
;
// Enter the name to creating zipped foldee
$zipcreated
=
"Nameofzip.zip"
;
// Create new zip class
$zip
=
new
ZipArchive;
if
(
$zip
-> open(
$zipcreated
, ZipArchive::CREATE ) === TRUE) {
// Store the path into the variable
$dir
= opendir(
$pathdir
);
while
(
$file
= readdir(
$dir
)) {
if
(
is_file
(
$pathdir
.
$file
)) {
$zip
-> addFile(
$pathdir
.
$file
,
$file
);
}
}
$zip
->close();
}
?>