Edmonds Commerce Logo
  • home
    • blog
  • ecommerce
    • product catalogue
    • order processing
    • customer services
    • stock control
    • human resources
    • management information
  • development
    • oscommerce
    • php
    • mysql
    • open source
    • performance tuning
  • design
  • marketing
  • contact us
    • pricing

Edmonds Commerce Blog

Freelance PHP Ecommerce and SEO Developer in the UK

Latest Posts

Securing a LAMP Server with mod_security
osCommerce Easypopulate File Creator Class
CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc

Most Popular Posts

PHP Email Attachment Function Freelance osCommerce UK Ultimate osCommerce Checkout - Fast and Friendly PHP : Dead Easy Excel Export

PHP and Zip Files

March 13th, 2008
Read More php, zip

There aren't many things you can't do with PHP. One of the things you can do is deal with zip files.

PHP has a built in class for dealing with zip files which allows you to create them, unpack them, add and delete things from them and generally use them within your scripts.

Recently on a spidering / product feed integration job that I have been working on I needed to grab a load of image zip files and unpack them all into a folder called 'images/' (surprisingly enough)

Here is how I did it:

PLAIN TEXT
PHP:
  1. function unpack_zips($directory, $destination = 'images/'){
  2.     $files = dir_list($directory);
  3.     //print_r($files);
  4.     $zips = array();
  5.     foreach($files as $k=>$file){
  6.         if(stristr($file, '.zip')){
  7.             $zips[] = $directory . $file;
  8.         }
  9.     }
  10.     print_r($zips);
  11.     $zip = new ZipArchive;
  12.     foreach($zips as $z){
  13.         if ($zip->open($z) === TRUE) {
  14.             $zip->extractTo($directory . $destination);
  15.             $zip->close();
  16.             //echo "<h3>$z OK</h3>";
  17.         } else {
  18.             echo"<h3 style=\"color: red;\">$z Failed</h3>";
  19.             bottom();
  20.         }   
  21.     }
  22. }
  23.  
  24. function dir_list($directory){
  25.     echo $directory;
  26.     if ($handle = opendir($directory)) {
  27.         while (false !== ($file = readdir($handle))) {
  28.             if($file != '.' && $file != '..'){
  29.                 $return[] = $file;
  30.             }
  31.         }
  32.         closedir($handle);
  33.         return $return;
  34.     }else{   
  35.         return false;
  36.     }
  37. }

There are two functions. The first function is the one that deals with the Zip files. The second function is called by the first function and simply lists all files within a specified directory.

These two functions combined allowed me to find all zip files in a particular folder and then unpack them all into a destination folder.

Related Resources

http://www.phpclasses.org/browse/package/945.html

http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/

Bookmark this Post
Add 'PHP and Zip Files' to Del.icio.usAdd 'PHP and Zip Files' to diggAdd 'PHP and Zip Files' to FURLAdd 'PHP and Zip Files' to blinklistAdd 'PHP and Zip Files' to redditAdd 'PHP and Zip Files' to Feed Me LinksAdd 'PHP and Zip Files' to TechnoratiAdd 'PHP and Zip Files' to Yahoo My WebAdd 'PHP and Zip Files' to NewsvineAdd 'PHP and Zip Files' to SocializerAdd 'PHP and Zip Files' to Ma.gnoliaAdd 'PHP and Zip Files' to Stumble UponAdd 'PHP and Zip Files' to Google BookmarksAdd 'PHP and Zip Files' to RawSugarAdd 'PHP and Zip Files' to SquidooAdd 'PHP and Zip Files' to SpurlAdd 'PHP and Zip Files' to BlinkBitsAdd 'PHP and Zip Files' to NetvouzAdd 'PHP and Zip Files' to RojoAdd 'PHP and Zip Files' to BlogmarksAdd 'PHP and Zip Files' to ShadowsAdd 'PHP and Zip Files' to Co.mments
Add 'PHP and Zip Files' to ScuttleAdd 'PHP and Zip Files' to BloglinesAdd 'PHP and Zip Files' to TailrankAdd 'PHP and Zip Files' to SegnaloAdd 'PHP and Zip Files' to OKnotizieAdd 'PHP and Zip Files' to NetscapeAdd 'PHP and Zip Files' to Bookmark.itAdd 'PHP and Zip Files' to AskAdd 'PHP and Zip Files' to SmarkingAdd 'PHP and Zip Files' to LinkagogoAdd 'PHP and Zip Files' to DeliriousAdd 'PHP and Zip Files' to SocialdustAdd 'PHP and Zip Files' to Live-MSNAdd 'PHP and Zip Files' to SlashDotAdd 'PHP and Zip Files' to SphinnAdd 'PHP and Zip Files' to DiggitaAdd 'PHP and Zip Files' to SeotribuAdd 'PHP and Zip Files' to FaceBookAdd 'PHP and Zip Files' to UpnewsAdd 'PHP and Zip Files' to WikioAdd 'PHP and Zip Files' to Social Bookmarking Reloaded

Feed | Respond | Trackback

Leave a Reply

  • RSS Feed
  • Categories

    • apache
    • barcode
    • creloaded
    • curl
    • customer services
    • debugging
    • ecommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • magento
    • management
    • mod_rewrite
    • mysql
    • oscommerce
    • php
    • plesk
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • scraping
    • search engine optimisation
    • security
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    addons advanced adverts blackhat blocking css curl development directories find firefox google hosts file html javascript keywords links msn mysql myths operators oscommerce paid links paid placement performance php ppc reciprocal linking replace screen scraping security seo serp speed spider spidering tuning user friendly vista web web design web developer
  • Random Posts

    • Chemos SEO URLS for osCommerce
    • Apache, mod_rewrite and SEO
    • ICECat Integration with osCommerce, Magento etc
    • Developing Web Applications in Windows
    • Product Feed Integration and Scraping Products from Supplier Web Sites
    • MySQL Dump Partial Restore - Split MySQL Dump into Tables
    • Freelance osCommerce UK
    • PHP: Recursive Create Path (if not exists)
    • osCommerce Output Queries Debug : Store Speed Optimisation
    • Saving a File or Webpage using PHP

Edmonds Commerce related questions? Send us a message or call us on 0844 357 0201.

Freelance PHP Web Design UK Commercial Web Design