Making ZIP file using php
createZip.inc.php
<?php
include_once(“createZip.inc.php”);
$createZip = new createZip;
$createZip -> addDirectory(“dir/”);
$allowed_types = array(‘png’,’jpg’,’jpeg’,’gif’); // list of filetypes you want to show
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img); // total image number
for($x=0; $x < $totimg; $x++)
{
$size = getimagesize($imgdir.’/’.$a_img[$x]);
// do whatever
//$halfwidth = ceil($size[0]/2);
//$halfheight = ceil($size[1]/2);
$fileContents = file_get_contents($a_img[$x]);
// echo ‘name: ‘.$a_img[$x].’ width: ‘.$size[0].’ height: ‘.$size[1].'<br />’;
}
$fileName = “archive.zip”;
$fd = fopen ($fileName, “wb”);
$out = fwrite ($fd, $createZip -> getZippedfile());
fclose ($fd);
$createZip -> forceDownload($fileName);
@unlink($fileName);
?>
View.php
<?php
include_once(“createZip.inc.php”);
$createZip = new createZip;
$createZip -> addDirectory(“dir/”);
$allowed_types = array(‘png’,’jpg’,’jpeg’,’gif’); // list of filetypes you want to show
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img); // total image number
for($x=0; $x < $totimg; $x++)
{
$size = getimagesize($imgdir.’/’.$a_img[$x]);
// do whatever
//$halfwidth = ceil($size[0]/2);
//$halfheight = ceil($size[1]/2);
$fileContents = file_get_contents($a_img[$x]);
// echo ‘name: ‘.$a_img[$x].’ width: ‘.$size[0].’ height: ‘.$size[1].'<br />’;
}
$fileName = “archive.zip”;
$fd = fopen ($fileName, “wb”);
$out = fwrite ($fd, $createZip -> getZippedfile());
fclose ($fd);
$createZip -> forceDownload($fileName);
@unlink($fileName);
?>