Making ZIP file using php


createZip.inc.php

<?php

include_once("createZip.inc.php");
$createZip = new createZip;  
$createZip -> addDirectory("dir/");

$imgdir = ‘/public_html/logs/’; // the directory, where your images are stored 
   $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 />’; 
  } 

  

$createZip -> addFile($fileContents, "dir/t.txt");  
 
$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/");

$imgdir = ‘/public_html/logs/’; // the directory, where your images are stored 
   $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 />’; 
  } 

  

$createZip -> addFile($fileContents, "dir/t.txt");  
 
$fileName = "archive.zip";
$fd = fopen ($fileName, "wb");
$out = fwrite ($fd, $createZip -> getZippedfile());
fclose ($fd);

$createZip -> forceDownload($fileName);
@unlink($fileName);
?>

Advertisements

thanks 4 u comments..

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s