The Official Blog of Patcoola

Im just a dude watching over my parents,
and trying to make cartoons and video games from home.

Script: ZIP API 2 [PHP Class]

, By Patcoola

Script Title: zipAPI
Programming Language: PHP5
Date Completed: 2016-02-07

Purpose: Easily create and extract ZIP archives.

Description: PHP class for creating and extracting ZIP archives. Provides easy to use functions and powerful features.

Advertisement

Donate Now!

I don't always use the women's bathroom, but when I do, you can bet it really smells. If you like my blog, please consider donating.


Method:

set_defaults();

Function to reset all options to their defaults.

set_overwrite( BOOLEAN );

Option to overwrite an existing zip file if it already exists. Default value false.

set_include_dirname( BOOLEAN );

Option to include the parent folder name when creating a zip file. Default value true. If set to false, only the contents of the selected folder will be archived.

exclude_extension( STRING );

Function to add a file extension to be excluded while creating an archive.
Note: also allows wild cards * ?.

exclude_file( STRING );

Function to add a file (full path) or file name to be excluded while creating an archive.
Note: also allows wild cards * ?.

exclude_folder( STRING );

Function to add a folder (full path) or folder name to be excluded while creating an archive.
Note: also allows wild cards * ?.

clear_exclude_extensions();

Function to remove all extensions from the exclusion list.

clear_exclude_files();

Function to remove all files from the exclusion list.

clear_exclude_folders();

Function to remove all folders from the exclusion list.

error_console();

Function to return an array of error messages. Returns an array.

fileExists( ZIPFILE = “”, FIND = “”, [case insensitive = false] );

Function to determine if a file or directory exists in an archive. Returns true or false. Will return false if an error has occurred.

numFiles( ZIPFILE = “” );

Function to count the number of entries in the archive. Entries include files and folders. Returns a number. Will return false if an error has occurred.

scanArchive( ZIPFILE = “”, [MODE = 0/1] );

Function to list all files and directories in an archive. Returns an array.
Mode 0 (default): Returns only the files and directories.
Mode 1: Returns all archive details.
Will return false if an error has occurred.

extractTo( ZIPFILE = “”, DESTINATION_PATH = “” );

Function to extract a zip file to a given path. Returns true or false. Will return false if an error has occurred.

createTo( TARGET_PATH = “”, DESTINATION_PATH = “” );

Function to create a zip file from a given path. Returns true or false. Will return false if an error has occurred.

Example Usage:

$nuZip = new zipAPI();

if ( !$nuZip->createTo(“../FileMan2”, “../newarchive.zip”) ) {

echo “Errors:”;
print_r ( $nuZip->error_console() );

} else {

echo “Complete”;

if ( !empty($nuZip->error_console()) ) {

echo “Errors:”;
print_r ( $nuZip->error_console() );

}

}

 

Advertisement

Donate Now!

This might not be the best time, but making a blog is not easy. Would you consider donating?


 

Post Meta

Share Post

 

Comments: Write Comment

Be the first to write a comment.


Leave a Comment


All comments are reviewed before publishing. Comments must be related to the page topic, must not be spam, and must comply with the criminal code of Canada.