Go Back   Webmaster Forums UK SEO SEM Webmaster Community Forum - UKWW > Web Design and Website Development > Programming > PHP Forum
Register FAQ Members List Downloads Calendar Today's Posts Webmaster Resources Webmaster Blogs
 
 

PHP Forum PHP related discussion, help, tips and tutorials.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2008, 09:39 PM
istanbul's Avatar
Senior Member
377 posts this year. worth their weight in gold!
Trusted Member - And full of good stuff!
 
Join Date: Dec 2007
Location: ||||||%75 loading
Posts: 263
Thanks: 1
Thanked 1 Time in 1 Post
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Send a message via MSN to istanbul
Lightbulb ZIPing Files (PHP)

PHP Code:
<?php  
class zipfile    
{    
  var 
$datasec = array(); // array to store compressed data  
  
var $ctrl_dir = array(); // central directory     
  
var $eof_ctrl_dir "\x50\x4b\x05\x06\x00\x00\x00\x00"//end of Central directory record  
  
var $old_offset 0;  

  function 
add_dir($name)     
  {    
    
// adds "directory" to archive - do this before putting any files in directory!  
    // $name - name of directory... like this: "path/"  
    // ...then you can add files using add_file with names like "path/file.txt"  
    
$name str_replace("\\""/"$name);    

    
$fr "\x50\x4b\x03\x04";  
    
$fr .= "\x0a\x00";    // ver needed to extract  
    
$fr .= "\x00\x00";    // gen purpose bit flag  
    
$fr .= "\x00\x00";    // compression method  
    
$fr .= "\x00\x00\x00\x00"// last mod time and date  

    
$fr .= pack("V",0); // crc32  
    
$fr .= pack("V",0); //compressed filesize  
    
$fr .= pack("V",0); //uncompressed filesize  
    
$fr .= pack("v"strlen($name) ); //length of pathname  
    
$fr .= pack("v"); //extra field length  
    
$fr .= $name;   
    
// end of "local file header" segment  

    // no "file data" segment for path  

    // "data descriptor" segment (optional but necessary if archive is not served as file)  

    
$fr .= pack("V",$crc); //crc32  
    
$fr .= pack("V",$c_len); //compressed filesize  
    
$fr .= pack("V",$unc_len); //uncompressed filesize  

    // add this entry to array  
    
$this -> datasec[] = $fr;  

    
$new_offset strlen(implode(""$this->datasec));  

    
// ext. file attributes mirrors MS-DOS directory attr byte, detailed  
    // at http://support.microsoft.com/support/kb/articles/Q125/0/19.asp  

    // now add to central record  
    
$cdrec "\x50\x4b\x01\x02";  
    
$cdrec .="\x00\x00";    // version made by  
    
$cdrec .="\x0a\x00";    // version needed to extract  
    
$cdrec .="\x00\x00";    // gen purpose bit flag  
    
$cdrec .="\x00\x00";    // compression method  
    
$cdrec .="\x00\x00\x00\x00"// last mod time & date  
    
$cdrec .= pack("V",0); // crc32  
    
$cdrec .= pack("V",0); //compressed filesize  
    
$cdrec .= pack("V",0); //uncompressed filesize  
    
$cdrec .= pack("v"strlen($name) ); //length of filename  
    
$cdrec .= pack("v"); //extra field length     
    
$cdrec .= pack("v"); //file comment length  
    
$cdrec .= pack("v"); //disk number start  
    
$cdrec .= pack("v"); //internal file attributes  
    
$ext "\x00\x00\x10\x00";  
    
$ext "\xff\xff\xff\xff";    
    
$cdrec .= pack("V"16 ); //external file attributes  - 'directory' bit set  

    
$cdrec .= pack("V"$this -> old_offset ); //relative offset of local header  
    
$this -> old_offset $new_offset;  

    
$cdrec .= $name;    
    
// optional extra field, file comment goes here  
    // save to array  
    
$this -> ctrl_dir[] = $cdrec;    
  }  
  function 
add_file($data$name)     
  
// adds "file" to archive     
  // $data - file contents  
  // $name - name of file in archive. Add path if your want  
  
{    
    
$name str_replace("\\""/"$name);    
    
//$name = str_replace("\\", "\\\\", $name);  
    
$fr "\x50\x4b\x03\x04";  
    
$fr .= "\x14\x00";    // ver needed to extract  
    
$fr .= "\x00\x00";    // gen purpose bit flag  
    
$fr .= "\x08\x00";    // compression method  
    
$fr .= "\x00\x00\x00\x00"// last mod time and date  

    
$unc_len strlen($data);    
    
$crc crc32($data);    
    
$zdata gzcompress($data);    
    
$zdata substrsubstr($zdata0strlen($zdata) - 4), 2); // fix crc bug  
    
$c_len strlen($zdata);    
    
$fr .= pack("V",$crc); // crc32  
    
$fr .= pack("V",$c_len); //compressed filesize  
    
$fr .= pack("V",$unc_len); //uncompressed filesize  
    
$fr .= pack("v"strlen($name) ); //length of filename  
    
$fr .= pack("v"); //extra field length  
    
$fr .= $name;    
    
// end of "local file header" segment  
               
    // "file data" segment  
    
$fr .= $zdata;    

    
// "data descriptor" segment (optional but necessary if archive is not served as file)  
    
$fr .= pack("V",$crc); //crc32  
    
$fr .= pack("V",$c_len); //compressed filesize  
    
$fr .= pack("V",$unc_len); //uncompressed filesize  

    // add this entry to array  
    
$this -> datasec[] = $fr;  

    
$new_offset strlen(implode(""$this->datasec));  

    
// now add to central directory record  
    
$cdrec "\x50\x4b\x01\x02";  
    
$cdrec .="\x00\x00";    // version made by  
    
$cdrec .="\x14\x00";    // version needed to extract  
    
$cdrec .="\x00\x00";    // gen purpose bit flag  
    
$cdrec .="\x08\x00";    // compression method  
    
$cdrec .="\x00\x00\x00\x00"// last mod time & date  
    
$cdrec .= pack("V",$crc); // crc32  
    
$cdrec .= pack("V",$c_len); //compressed filesize  
    
$cdrec .= pack("V",$unc_len); //uncompressed filesize  
    
$cdrec .= pack("v"strlen($name) ); //length of filename  
    
$cdrec .= pack("v"); //extra field length     
    
$cdrec .= pack("v"); //file comment length  
    
$cdrec .= pack("v"); //disk number start  
    
$cdrec .= pack("v"); //internal file attributes  
    
$cdrec .= pack("V"32 ); //external file attributes - 'archive' bit set  

    
$cdrec .= pack("V"$this -> old_offset ); //relative offset of local header  
    //      &n // bsp; echo "old offset is ".$this->old_offset.", new offset is $new_offset<br>";  
    
$this -> old_offset $new_offset;  

    
$cdrec .= $name;    
    
// optional extra field, file comment goes here  
    // save to central directory  
    
$this -> ctrl_dir[] = $cdrec;    
  }  
  function 
file() { // dump out file     
    
$data implode(""$this -> datasec);    
    
$ctrldir implode(""$this -> ctrl_dir);    
    return     
      
$data.    
      
$ctrldir.    
      
$this -> eof_ctrl_dir.    
      
pack("v"sizeof($this -> ctrl_dir)).     // total # of entries "on this disk"  
      
pack("v"sizeof($this -> ctrl_dir)).     // total # of entries overall  
      
pack("V"strlen($ctrldir)).             // size of central dir  
      
pack("V"strlen($data)).                 // offset to start of central dir  
      
"\x00\x00";                             // .zip file comment length  
  
}  
}    
?>  


EXAMPLE  
<?php  
  $zipfile 
= new zipfile();    

  
// If you want to add new ZIP folder
  
  
$zipfile -> add_dir("dir/");  

  
// ZIP folder's content  
  
$filedata "write what you want to write in ZIP folder";    
  
$zipfile -> add_file($filedata"dir/file.txt");    

  
// If you want to download ZIP folder
  
header("Content-type: application/octet-stream");    
  
header("Content-disposition: attachment; filename=test.zip");    
  echo 
$zipfile -> file();    


  
// If you want to register your ZIP file to your server  
  
$filename "output.zip";  
  
$fd fopen ($filename"wb");  
  
$out fwrite ($fd$zipfile -> file());  
  
fclose ($fd);  
?>
I hope that code helps someone...
__________________
TAGS: pırlanta araba kiralama istanbul
Forums.UkWebMasterWorld.com | "Green Rep Appreciated"
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 01-31-2008, 09:53 PM
SkinnerW's Avatar
Senior Member
1566 posts this year. Platinum VIP!
Trusted Member - This user is a Master!
 
Join Date: Jun 2007
Location: Moscow - New York
Posts: 1,386
Thanks: 0
Thanked 1 Time in 1 Post
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Send a message via Yahoo to SkinnerW
Default

Can you describe in more details what is the purpose of this script and how one can benefit from it.

Not all of our users are advanced programmers...

Thanks
__________________
Advanced CMS software with directory, blog, classifieds and portal features
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 01-31-2008, 10:00 PM
istanbul's Avatar
Senior Member
377 posts this year. worth their weight in gold!
Trusted Member - And full of good stuff!
 
Join Date: Dec 2007
Location: ||||||%75 loading
Posts: 263
Thanks: 1
Thanked 1 Time in 1 Post
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Send a message via MSN to istanbul
Default

Quote:
Originally Posted by SkinnerW View Post
Can you describe in more details what is the purpose of this script and how one can benefit from it.

Not all of our users are advanced programmers...

Thanks
You'r Welcome

This code is using for ziping files but i didnt use it
It was in my library and i wanted to share it..
__________________
TAGS: pırlanta araba kiralama istanbul
Forums.UkWebMasterWorld.com | "Green Rep Appreciated"
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 02-01-2008, 02:37 AM
Member
44 posts this year. i see smoke!
It looks like they have moved their luggage in.
 
Join Date: Dec 2007
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Default

nice library, this can be apply in wallpaper site specifically in download area. If the person want to download several wallpaper you just need another application that enable user to choose from different wallpaper and after that all chosen wallpaper will be zip (using the library) and ready for download.
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 02-01-2008, 10:04 AM
istanbul's Avatar
Senior Member
377 posts this year. worth their weight in gold!
Trusted Member - And full of good stuff!
 
Join Date: Dec 2007
Location: ||||||%75 loading
Posts: 263
Thanks: 1
Thanked 1 Time in 1 Post
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Send a message via MSN to istanbul
Default

Quote:
Originally Posted by eli03 View Post
nice library, this can be apply in wallpaper site specifically in download area. If the person want to download several wallpaper you just need another application that enable user to choose from different wallpaper and after that all chosen wallpaper will be zip (using the library) and ready for download.

Thank you so much for understanding me
__________________
TAGS: pırlanta araba kiralama istanbul
Forums.UkWebMasterWorld.com | "Green Rep Appreciated"
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 02-01-2008, 04:59 PM
Banned
312 posts this year. worth their weight in gold!
Trusted Member - And full of good stuff!
 
Join Date: Oct 2007
Posts: 257
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Send a message via MSN to Scripter Send a message via Yahoo to Scripter
Default

Nice script.
Very clean too.
Ill add you some rep for that!
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Webmaster Resources
UK WW SEO Tools
Find UK Hosts
 
The Forum Rules
Forum Rules - MUST READ
 
Site Of the Month
BizzFace
Nominate site of the month
 
Tag Cloud
affiliates ambitious asbestos cancer bid bidding directory bid directory bid directory list bid for position business clothes contest cricket writer delisted designer discount ecommerce email list email marketing finance forum free web hosting free website hosting global business directory google handbags huge email database internet and marketing jewelry link submissions niche of mesothelioma phones electronics php file value pr7 directory replica social bookmark startup sunglasses technology wallets web web design web development website website for sale website promotion websites for sale wholesale yahoo backlink

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump