Page 1 of 1

How to create and delete zip folders using PHP

Posted: Fri Sep 09, 2016 11:56 am
by ashi4275
Hi, I am an application developer. While working on a project, I faced an issue related to creating and deleting zip folders using PHP. I hope any tech developer may help me in resolving this issue. I have also figure out many mobile development forum to enhance my android & IOS programming knowledge & it's a great experience to learn skills from there.

Re: How to create and delete zip folders using PHP

Posted: Mon Sep 12, 2016 6:00 am
by amar9450
I understand your problem.you can tray this

<?php
$directory = "send_sms/";
//create zip object
$zip = new ZipArchive();
$zip_name = time().".send_sms";
$zip->open($zip_name, ZipArchive::CREATE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($directory),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $file) {
$path = $file->getRealPath();
//check file permission
if(fileperms($path)!="16895"){
$zip->addFromString(basename($path), file_get_contents($path)) ;
echo "<span style='color:green;'>{$path} is added to zip file.<br /></span> " ;
}
else{
echo"<span style='color:red;'>{$path} location could not be added to zip<br /></span>";
}
}
$zip->close();
?>