Go Back   Internet Business Forums > Design & Development

Reply
 
Thread Tools Display Modes
Old 25-11-2006, 07:50 PM   #1 (permalink)
co-admin
 
army's Avatar
 
Join Date: Oct 2006
Location: Belgium
Posts: 666
Default [ SCRIPT ] PHP Unzipper!

With this function, you can extract automatically ZIP-files on your server.
I personally use it in combination with an uploader.

More specific for a photo-gallery . But you also can use it for different purpose .


ATTENTION:
This file (the function) and the ZIP-file have to be CHMODed to 77, otherwise it won't work!


PHP Code:
<?php
// The function
function unpackZip($dir,$file) {
   if (
$zip zip_open($dir.$file.".zip")) {
     if (
$zip) {
       
mkdir($dir.$file);
       while (
$zip_entry zip_read($zip)) {
         if (
zip_entry_open($zip,$zip_entry,"r")) {
           
$buf zip_entry_read($zip_entryzip_entry_filesize($zip_entry));
           
$dir_name dirname(zip_entry_name($zip_entry));
           if (
$dir_name != ".") {
             
$dir_op $dir.$file."/";
               foreach ( 
explode("/",$dir_name) as $k) {
                 
$dir_op $dir_op $k;
                 if (
is_file($dir_op)) unlink($dir_op);
                 if (!
is_dir($dir_op)) mkdir($dir_op);
                 
$dir_op $dir_op "/" ;
                 }
               }
           
$fp=fopen($dir.$file."/".zip_entry_name($zip_entry),"w");
           
fwrite($fp,$buf);
           
zip_entry_close($zip_entry);
       } else
           return 
false;
       }
       
zip_close($zip);
     }
  } else
     return 
false;

  return 
true;
}

// The use of the script
$plaats  "bestanden/files/"// The directory where the ZIP-files are upload to ATTENTION: directory ends with a slash (/) !!
$naam   "afbeeldingen"// This is the destination-directory
unpackZip($plaats,$naam);
?>
army is offline   Reply With Quote
Old 25-11-2006, 08:27 PM   #2 (permalink)
I am not *****
 
Join Date: Aug 2006
Location: Pakistan
Posts: 370
Default Re: [ SCRIPT ] PHP Unzipper!

Good job army . It really helped me. (REP ADDED + REWARDED already )
-FR- is offline   Reply With Quote
Old 26-11-2006, 04:44 PM   #3 (permalink)
Junior Member
 
Join Date: Nov 2006
Posts: 29
Default Re: [ SCRIPT ] PHP Unzipper!

How is it useful?
I use the unzip function in Cpanel.
It is useful only for people who do not use Cpanel.
Anyway it is a nice script to for beginners to understand how to code in PHP.
bbalegere is offline   Reply With Quote
Old 26-11-2006, 07:40 PM   #4 (permalink)
co-admin
 
army's Avatar
 
Join Date: Oct 2006
Location: Belgium
Posts: 666
Default Re: [ SCRIPT ] PHP Unzipper!

Quote:
Originally Posted by bbalegere View Post
How is it useful?
I use the unzip function in Cpanel.
It is useful only for people who do not use Cpanel.
Anyway it is a nice script to for beginners to understand how to code in PHP.
Uhm, with all do respect ... but it is not just a script for beginners . I will tell you how I use... and I also DO have a hjost with cPanel!

I have a photogallery installed on my school's site. Teachers have a special teachers-panel on that site, and they can upoad pictures to there. But I put there they should make a ZIP with all pictures inside, and upload it then, because it takes less time to upload. Then I logon on the admin-panel, and I run this script ... so when all files are extracted, they are also immediatly aded to the gallery, and they are even up there.

So, that is an example of using it, and it is not just for "beginners" who want to learn PHP. It is for many more features good .
army is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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 Off


All times are GMT +1. The time now is 07:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.