system/libraries/Zip.php
.htaccess
AesEncryption.php
LICENSE
application
.htaccess
cache
index.html
config
autoload.php
config.php
constants.php
database.php
doctypes.php
foreign_chars.php
hooks.php
index.html
memcached.php
migration.php
mimes.php
profiler.php
routes.php
smileys.php
user_agents.php
controllers
Systemid.php
Welcome.php
index.html
core
index.html
helpers
index.html
hooks
index.html
index.html
language
english
index.html
system_lang.php
index.html
libraries
index.html
logs
index.html
models
System_model.php
index.html
third_party
index.html
views
about.php
category
addedit.php
addeditsub.php
components.php
delete.php
errors
cli
error_404.php
error_db.php
error_exception.php
error_general.php
error_php.php
index.html
html
error_404.php
error_db.php
error_exception.php
error_general.php
error_php.php
index.html
index.html
foot.php
generator.php
head.php
index.html
login.php
main.php
pass
addedit.php
show.php
welcome_message.php
captcha
sys.txt
favicon.ico
index.php
install.php
library
AesEncryption.php
bootstrap
css
.DS_Store
bootstrap-grid.css
bootstrap-grid.css.map
bootstrap-grid.min.css
bootstrap-grid.min.css.map
bootstrap-reboot.css
bootstrap-reboot.css.map
bootstrap-reboot.min.css
bootstrap-reboot.min.css.map
bootstrap.css
bootstrap.css.map
bootstrap.min.css
bootstrap.min.css.map
js
bootstrap.bundle.js
bootstrap.bundle.js.map
bootstrap.bundle.min.js
bootstrap.bundle.min.js.map
bootstrap.js
bootstrap.js.map
bootstrap.min.js
bootstrap.min.js.map
font-awesome
HELP-US-OUT.txt
css
font-awesome.css
font-awesome.min.css
fonts
FontAwesome.otf
fontawesome-webfont.eot
fontawesome-webfont.svg
fontawesome-webfont.ttf
fontawesome-webfont.woff
fontawesome-webfont.woff2
less
animated.less
bordered-pulled.less
core.less
fixed-width.less
font-awesome.less
icons.less
larger.less
list.less
mixins.less
path.less
rotated-flipped.less
screen-reader.less
stacked.less
variables.less
scss
_animated.scss
_bordered-pulled.scss
_core.scss
_fixed-width.scss
_icons.scss
_larger.scss
_list.scss
_mixins.scss
_path.scss
_rotated-flipped.scss
_screen-reader.scss
_stacked.scss
_variables.scss
font-awesome.scss
font-awesome.min.css
jquery-ui
AUTHORS.txt
LICENSE.txt
external
jquery
jquery.js
images
ui-icons_444444_256x240.png
ui-icons_555555_256x240.png
ui-icons_777620_256x240.png
ui-icons_777777_256x240.png
ui-icons_cc0000_256x240.png
ui-icons_ffffff_256x240.png
index.html
jquery-ui.css
jquery-ui.js
jquery-ui.min.css
jquery-ui.min.js
jquery-ui.structure.css
jquery-ui.structure.min.css
jquery-ui.theme.css
jquery-ui.theme.min.css
package.json
jquery.min.js
jquerysctipttop.css
logo.png
password_indicator_bs4
css
signin.css
index.html
js
jaktutorial.js
popper.min.js
right-click
css
contextMenu.min.css
js
contextMenu.min.js
style.css
tether
css
tether-theme-arrows-dark.css
tether-theme-arrows-dark.min.css
tether-theme-arrows.css
tether-theme-arrows.min.css
tether-theme-basic.css
tether-theme-basic.min.css
tether.css
tether.min.css
js
tether.js
tether.min.js
system
.htaccess
core
Benchmark.php
CodeIgniter.php
Common.php
Config.php
Controller.php
Exceptions.php
Hooks.php
Input.php
Lang.php
Loader.php
Log.php
Model.php
Output.php
Router.php
Security.php
URI.php
Utf8.php
compat
hash.php
index.html
mbstring.php
password.php
standard.php
index.html
database
DB.php
DB_cache.php
DB_driver.php
DB_forge.php
DB_query_builder.php
DB_result.php
DB_utility.php
drivers
cubrid
cubrid_driver.php
cubrid_forge.php
cubrid_result.php
cubrid_utility.php
index.html
ibase
ibase_driver.php
ibase_forge.php
ibase_result.php
ibase_utility.php
index.html
index.html
mssql
index.html
mssql_driver.php
mssql_forge.php
mssql_result.php
mssql_utility.php
mysql
index.html
mysql_driver.php
mysql_forge.php
mysql_result.php
mysql_utility.php
mysqli
index.html
mysqli_driver.php
mysqli_forge.php
mysqli_result.php
mysqli_utility.php
oci8
index.html
oci8_driver.php
oci8_forge.php
oci8_result.php
oci8_utility.php
odbc
index.html
odbc_driver.php
odbc_forge.php
odbc_result.php
odbc_utility.php
pdo
index.html
pdo_driver.php
pdo_forge.php
pdo_result.php
pdo_utility.php
subdrivers
index.html
pdo_4d_driver.php
pdo_4d_forge.php
pdo_cubrid_driver.php
pdo_cubrid_forge.php
pdo_dblib_driver.php
pdo_dblib_forge.php
pdo_firebird_driver.php
pdo_firebird_forge.php
pdo_ibm_driver.php
pdo_ibm_forge.php
pdo_informix_driver.php
pdo_informix_forge.php
pdo_mysql_driver.php
pdo_mysql_forge.php
pdo_oci_driver.php
pdo_oci_forge.php
pdo_odbc_driver.php
pdo_odbc_forge.php
pdo_pgsql_driver.php
pdo_pgsql_forge.php
pdo_sqlite_driver.php
pdo_sqlite_forge.php
pdo_sqlsrv_driver.php
pdo_sqlsrv_forge.php
postgre
index.html
postgre_driver.php
postgre_forge.php
postgre_result.php
postgre_utility.php
sqlite
index.html
sqlite_driver.php
sqlite_forge.php
sqlite_result.php
sqlite_utility.php
sqlite3
index.html
sqlite3_driver.php
sqlite3_forge.php
sqlite3_result.php
sqlite3_utility.php
sqlsrv
index.html
sqlsrv_driver.php
sqlsrv_forge.php
sqlsrv_result.php
sqlsrv_utility.php
index.html
fonts
index.html
texb.ttf
helpers
array_helper.php
captcha_helper.php
cookie_helper.php
date_helper.php
directory_helper.php
download_helper.php
email_helper.php
file_helper.php
form_helper.php
html_helper.php
index.html
inflector_helper.php
language_helper.php
number_helper.php
path_helper.php
security_helper.php
smiley_helper.php
string_helper.php
text_helper.php
typography_helper.php
url_helper.php
xml_helper.php
index.html
language
english
calendar_lang.php
date_lang.php
db_lang.php
email_lang.php
form_validation_lang.php
ftp_lang.php
imglib_lang.php
index.html
migration_lang.php
number_lang.php
pagination_lang.php
profiler_lang.php
unit_test_lang.php
upload_lang.php
index.html
libraries
Cache
Cache.php
drivers
Cache_apc.php
Cache_dummy.php
Cache_file.php
Cache_memcached.php
Cache_redis.php
Cache_wincache.php
index.html
index.html
Calendar.php
Cart.php
Driver.php
Email.php
Encrypt.php
Encryption.php
Form_validation.php
Ftp.php
Image_lib.php
Javascript
Jquery.php
index.html
Javascript.php
Migration.php
Pagination.php
Parser.php
Profiler.php
Session
Session.php
SessionHandlerInterface.php
Session_driver.php
drivers
Session_database_driver.php
Session_files_driver.php
Session_memcached_driver.php
Session_redis_driver.php
index.html
index.html
Table.php
Trackback.php
Typography.php
Unit_test.php
Upload.php
User_agent.php
Xmlrpc.php
Xmlrpcs.php
Zip.php
index.html
AesEncryption.php
LICENSE
application
.htaccess
cache
index.html
config
autoload.php
config.php
constants.php
database.php
doctypes.php
foreign_chars.php
hooks.php
index.html
memcached.php
migration.php
mimes.php
profiler.php
routes.php
smileys.php
user_agents.php
controllers
Systemid.php
Welcome.php
index.html
core
index.html
helpers
index.html
hooks
index.html
index.html
language
english
index.html
system_lang.php
index.html
libraries
index.html
logs
index.html
models
System_model.php
index.html
third_party
index.html
views
about.php
category
addedit.php
addeditsub.php
components.php
delete.php
errors
cli
error_404.php
error_db.php
error_exception.php
error_general.php
error_php.php
index.html
html
error_404.php
error_db.php
error_exception.php
error_general.php
error_php.php
index.html
index.html
foot.php
generator.php
head.php
index.html
login.php
main.php
pass
addedit.php
show.php
welcome_message.php
captcha
sys.txt
favicon.ico
index.php
install.php
library
AesEncryption.php
bootstrap
css
.DS_Store
bootstrap-grid.css
bootstrap-grid.css.map
bootstrap-grid.min.css
bootstrap-grid.min.css.map
bootstrap-reboot.css
bootstrap-reboot.css.map
bootstrap-reboot.min.css
bootstrap-reboot.min.css.map
bootstrap.css
bootstrap.css.map
bootstrap.min.css
bootstrap.min.css.map
js
bootstrap.bundle.js
bootstrap.bundle.js.map
bootstrap.bundle.min.js
bootstrap.bundle.min.js.map
bootstrap.js
bootstrap.js.map
bootstrap.min.js
bootstrap.min.js.map
font-awesome
HELP-US-OUT.txt
css
font-awesome.css
font-awesome.min.css
fonts
FontAwesome.otf
fontawesome-webfont.eot
fontawesome-webfont.svg
fontawesome-webfont.ttf
fontawesome-webfont.woff
fontawesome-webfont.woff2
less
animated.less
bordered-pulled.less
core.less
fixed-width.less
font-awesome.less
icons.less
larger.less
list.less
mixins.less
path.less
rotated-flipped.less
screen-reader.less
stacked.less
variables.less
scss
_animated.scss
_bordered-pulled.scss
_core.scss
_fixed-width.scss
_icons.scss
_larger.scss
_list.scss
_mixins.scss
_path.scss
_rotated-flipped.scss
_screen-reader.scss
_stacked.scss
_variables.scss
font-awesome.scss
font-awesome.min.css
jquery-ui
AUTHORS.txt
LICENSE.txt
external
jquery
jquery.js
images
ui-icons_444444_256x240.png
ui-icons_555555_256x240.png
ui-icons_777620_256x240.png
ui-icons_777777_256x240.png
ui-icons_cc0000_256x240.png
ui-icons_ffffff_256x240.png
index.html
jquery-ui.css
jquery-ui.js
jquery-ui.min.css
jquery-ui.min.js
jquery-ui.structure.css
jquery-ui.structure.min.css
jquery-ui.theme.css
jquery-ui.theme.min.css
package.json
jquery.min.js
jquerysctipttop.css
logo.png
password_indicator_bs4
css
signin.css
index.html
js
jaktutorial.js
popper.min.js
right-click
css
contextMenu.min.css
js
contextMenu.min.js
style.css
tether
css
tether-theme-arrows-dark.css
tether-theme-arrows-dark.min.css
tether-theme-arrows.css
tether-theme-arrows.min.css
tether-theme-basic.css
tether-theme-basic.min.css
tether.css
tether.min.css
js
tether.js
tether.min.js
system
.htaccess
core
Benchmark.php
CodeIgniter.php
Common.php
Config.php
Controller.php
Exceptions.php
Hooks.php
Input.php
Lang.php
Loader.php
Log.php
Model.php
Output.php
Router.php
Security.php
URI.php
Utf8.php
compat
hash.php
index.html
mbstring.php
password.php
standard.php
index.html
database
DB.php
DB_cache.php
DB_driver.php
DB_forge.php
DB_query_builder.php
DB_result.php
DB_utility.php
drivers
cubrid
cubrid_driver.php
cubrid_forge.php
cubrid_result.php
cubrid_utility.php
index.html
ibase
ibase_driver.php
ibase_forge.php
ibase_result.php
ibase_utility.php
index.html
index.html
mssql
index.html
mssql_driver.php
mssql_forge.php
mssql_result.php
mssql_utility.php
mysql
index.html
mysql_driver.php
mysql_forge.php
mysql_result.php
mysql_utility.php
mysqli
index.html
mysqli_driver.php
mysqli_forge.php
mysqli_result.php
mysqli_utility.php
oci8
index.html
oci8_driver.php
oci8_forge.php
oci8_result.php
oci8_utility.php
odbc
index.html
odbc_driver.php
odbc_forge.php
odbc_result.php
odbc_utility.php
pdo
index.html
pdo_driver.php
pdo_forge.php
pdo_result.php
pdo_utility.php
subdrivers
index.html
pdo_4d_driver.php
pdo_4d_forge.php
pdo_cubrid_driver.php
pdo_cubrid_forge.php
pdo_dblib_driver.php
pdo_dblib_forge.php
pdo_firebird_driver.php
pdo_firebird_forge.php
pdo_ibm_driver.php
pdo_ibm_forge.php
pdo_informix_driver.php
pdo_informix_forge.php
pdo_mysql_driver.php
pdo_mysql_forge.php
pdo_oci_driver.php
pdo_oci_forge.php
pdo_odbc_driver.php
pdo_odbc_forge.php
pdo_pgsql_driver.php
pdo_pgsql_forge.php
pdo_sqlite_driver.php
pdo_sqlite_forge.php
pdo_sqlsrv_driver.php
pdo_sqlsrv_forge.php
postgre
index.html
postgre_driver.php
postgre_forge.php
postgre_result.php
postgre_utility.php
sqlite
index.html
sqlite_driver.php
sqlite_forge.php
sqlite_result.php
sqlite_utility.php
sqlite3
index.html
sqlite3_driver.php
sqlite3_forge.php
sqlite3_result.php
sqlite3_utility.php
sqlsrv
index.html
sqlsrv_driver.php
sqlsrv_forge.php
sqlsrv_result.php
sqlsrv_utility.php
index.html
fonts
index.html
texb.ttf
helpers
array_helper.php
captcha_helper.php
cookie_helper.php
date_helper.php
directory_helper.php
download_helper.php
email_helper.php
file_helper.php
form_helper.php
html_helper.php
index.html
inflector_helper.php
language_helper.php
number_helper.php
path_helper.php
security_helper.php
smiley_helper.php
string_helper.php
text_helper.php
typography_helper.php
url_helper.php
xml_helper.php
index.html
language
english
calendar_lang.php
date_lang.php
db_lang.php
email_lang.php
form_validation_lang.php
ftp_lang.php
imglib_lang.php
index.html
migration_lang.php
number_lang.php
pagination_lang.php
profiler_lang.php
unit_test_lang.php
upload_lang.php
index.html
libraries
Cache
Cache.php
drivers
Cache_apc.php
Cache_dummy.php
Cache_file.php
Cache_memcached.php
Cache_redis.php
Cache_wincache.php
index.html
index.html
Calendar.php
Cart.php
Driver.php
Email.php
Encrypt.php
Encryption.php
Form_validation.php
Ftp.php
Image_lib.php
Javascript
Jquery.php
index.html
Javascript.php
Migration.php
Pagination.php
Parser.php
Profiler.php
Session
Session.php
SessionHandlerInterface.php
Session_driver.php
drivers
Session_database_driver.php
Session_files_driver.php
Session_memcached_driver.php
Session_redis_driver.php
index.html
index.html
Table.php
Trackback.php
Typography.php
Unit_test.php
Upload.php
User_agent.php
Xmlrpc.php
Xmlrpcs.php
Zip.php
index.html
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Zip Compression Class
*
* This class is based on a library I found at Zend:
* http://www.zend.com/codex.php?id=696&single=1
*
* The original library is a little rough around the edges so I
* refactored it and added several additional methods -- Rick Ellis
*
* @package CodeIgniter
* @subpackage Libraries
* @category Encryption
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/zip.html
*/
class CI_Zip {
/**
* Zip data in string form
*
* @var string
*/
public $zipdata = '';
/**
* Zip data for a directory in string form
*
* @var string
*/
public $directory = '';
/**
* Number of files/folder in zip file
*
* @var int
*/
public $entries = 0;
/**
* Number of files in zip
*
* @var int
*/
public $file_num = 0;
/**
* relative offset of local header
*
* @var int
*/
public $offset = 0;
/**
* Reference to time at init
*
* @var int
*/
public $now;
/**
* The level of compression
*
* Ranges from 0 to 9, with 9 being the highest level.
*
* @var int
*/
public $compression_level = 2;
/**
* mbstring.func_overload flag
*
* @var bool
*/
protected static $func_overload;
/**
* Initialize zip compression class
*
* @return void
*/
public function __construct()
{
isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
$this->now = time();
log_message('info', 'Zip Compression Class Initialized');
}
// --------------------------------------------------------------------
/**
* Add Directory
*
* Lets you add a virtual directory into which you can place files.
*
* @param mixed $directory the directory name. Can be string or array
* @return void
*/
public function add_dir($directory)
{
foreach ((array) $directory as $dir)
{
if ( ! preg_match('|.+/$|', $dir))
{
$dir .= '/';
}
$dir_time = $this->_get_mod_time($dir);
$this->_add_dir($dir, $dir_time['file_mtime'], $dir_time['file_mdate']);
}
}
// --------------------------------------------------------------------
/**
* Get file/directory modification time
*
* If this is a newly created file/dir, we will set the time to 'now'
*
* @param string $dir path to file
* @return array filemtime/filemdate
*/
protected function _get_mod_time($dir)
{
// filemtime() may return false, but raises an error for non-existing files
$date = file_exists($dir) ? getdate(filemtime($dir)) : getdate($this->now);
return array(
'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2,
'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday']
);
}
// --------------------------------------------------------------------
/**
* Add Directory
*
* @param string $dir the directory name
* @param int $file_mtime
* @param int $file_mdate
* @return void
*/
protected function _add_dir($dir, $file_mtime, $file_mdate)
{
$dir = str_replace('\\', '/', $dir);
$this->zipdata .=
"\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00"
.pack('v', $file_mtime)
.pack('v', $file_mdate)
.pack('V', 0) // crc32
.pack('V', 0) // compressed filesize
.pack('V', 0) // uncompressed filesize
.pack('v', self::strlen($dir)) // length of pathname
.pack('v', 0) // extra field length
.$dir
// below is "data descriptor" segment
.pack('V', 0) // crc32
.pack('V', 0) // compressed filesize
.pack('V', 0); // uncompressed filesize
$this->directory .=
"\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00"
.pack('v', $file_mtime)
.pack('v', $file_mdate)
.pack('V',0) // crc32
.pack('V',0) // compressed filesize
.pack('V',0) // uncompressed filesize
.pack('v', self::strlen($dir)) // length of pathname
.pack('v', 0) // extra field length
.pack('v', 0) // file comment length
.pack('v', 0) // disk number start
.pack('v', 0) // internal file attributes
.pack('V', 16) // external file attributes - 'directory' bit set
.pack('V', $this->offset) // relative offset of local header
.$dir;
$this->offset = self::strlen($this->zipdata);
$this->entries++;
}
// --------------------------------------------------------------------
/**
* Add Data to Zip
*
* Lets you add files to the archive. If the path is included
* in the filename it will be placed within a directory. Make
* sure you use add_dir() first to create the folder.
*
* @param mixed $filepath A single filepath or an array of file => data pairs
* @param string $data Single file contents
* @return void
*/
public function add_data($filepath, $data = NULL)
{
if (is_array($filepath))
{
foreach ($filepath as $path => $data)
{
$file_data = $this->_get_mod_time($path);
$this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']);
}
}
else
{
$file_data = $this->_get_mod_time($filepath);
$this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']);
}
}
// --------------------------------------------------------------------
/**
* Add Data to Zip
*
* @param string $filepath the file name/path
* @param string $data the data to be encoded
* @param int $file_mtime
* @param int $file_mdate
* @return void
*/
protected function _add_data($filepath, $data, $file_mtime, $file_mdate)
{
$filepath = str_replace('\\', '/', $filepath);
$uncompressed_size = self::strlen($data);
$crc32 = crc32($data);
$gzdata = self::substr(gzcompress($data, $this->compression_level), 2, -4);
$compressed_size = self::strlen($gzdata);
$this->zipdata .=
"\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00"
.pack('v', $file_mtime)
.pack('v', $file_mdate)
.pack('V', $crc32)
.pack('V', $compressed_size)
.pack('V', $uncompressed_size)
.pack('v', self::strlen($filepath)) // length of filename
.pack('v', 0) // extra field length
.$filepath
.$gzdata; // "file data" segment
$this->directory .=
"\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00"
.pack('v', $file_mtime)
.pack('v', $file_mdate)
.pack('V', $crc32)
.pack('V', $compressed_size)
.pack('V', $uncompressed_size)
.pack('v', self::strlen($filepath)) // length of filename
.pack('v', 0) // extra field length
.pack('v', 0) // file comment length
.pack('v', 0) // disk number start
.pack('v', 0) // internal file attributes
.pack('V', 32) // external file attributes - 'archive' bit set
.pack('V', $this->offset) // relative offset of local header
.$filepath;
$this->offset = self::strlen($this->zipdata);
$this->entries++;
$this->file_num++;
}
// --------------------------------------------------------------------
/**
* Read the contents of a file and add it to the zip
*
* @param string $path
* @param bool $archive_filepath
* @return bool
*/
public function read_file($path, $archive_filepath = FALSE)
{
if (file_exists($path) && FALSE !== ($data = file_get_contents($path)))
{
if (is_string($archive_filepath))
{
$name = str_replace('\\', '/', $archive_filepath);
}
else
{
$name = str_replace('\\', '/', $path);
if ($archive_filepath === FALSE)
{
$name = preg_replace('|.*/(.+)|', '\\1', $name);
}
}
$this->add_data($name, $data);
return TRUE;
}
return FALSE;
}
// ------------------------------------------------------------------------
/**
* Read a directory and add it to the zip.
*
* This function recursively reads a folder and everything it contains (including
* sub-folders) and creates a zip based on it. Whatever directory structure
* is in the original file path will be recreated in the zip file.
*
* @param string $path path to source directory
* @param bool $preserve_filepath
* @param string $root_path
* @return bool
*/
public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL)
{
$path = rtrim($path, '/\\').DIRECTORY_SEPARATOR;
if ( ! $fp = @opendir($path))
{
return FALSE;
}
// Set the original directory root for child dir's to use as relative
if ($root_path === NULL)
{
$root_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, dirname($path)).DIRECTORY_SEPARATOR;
}
while (FALSE !== ($file = readdir($fp)))
{
if ($file[0] === '.')
{
continue;
}
if (is_dir($path.$file))
{
$this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path);
}
elseif (FALSE !== ($data = file_get_contents($path.$file)))
{
$name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path);
if ($preserve_filepath === FALSE)
{
$name = str_replace($root_path, '', $name);
}
$this->add_data($name.$file, $data);
}
}
closedir($fp);
return TRUE;
}
// --------------------------------------------------------------------
/**
* Get the Zip file
*
* @return string (binary encoded)
*/
public function get_zip()
{
// Is there any data to return?
if ($this->entries === 0)
{
return FALSE;
}
return $this->zipdata
.$this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00"
.pack('v', $this->entries) // total # of entries "on this disk"
.pack('v', $this->entries) // total # of entries overall
.pack('V', self::strlen($this->directory)) // size of central dir
.pack('V', self::strlen($this->zipdata)) // offset to start of central dir
."\x00\x00"; // .zip file comment length
}
// --------------------------------------------------------------------
/**
* Write File to the specified directory
*
* Lets you write a file
*
* @param string $filepath the file name
* @return bool
*/
public function archive($filepath)
{
if ( ! ($fp = @fopen($filepath, 'w+b')))
{
return FALSE;
}
flock($fp, LOCK_EX);
for ($result = $written = 0, $data = $this->get_zip(), $length = self::strlen($data); $written < $length; $written += $result)
{
if (($result = fwrite($fp, self::substr($data, $written))) === FALSE)
{
break;
}
}
flock($fp, LOCK_UN);
fclose($fp);
return is_int($result);
}
// --------------------------------------------------------------------
/**
* Download
*
* @param string $filename the file name
* @return void
*/
public function download($filename = 'backup.zip')
{
if ( ! preg_match('|.+?\.zip$|', $filename))
{
$filename .= '.zip';
}
get_instance()->load->helper('download');
$get_zip = $this->get_zip();
$zip_content =& $get_zip;
force_download($filename, $zip_content);
}
// --------------------------------------------------------------------
/**
* Initialize Data
*
* Lets you clear current zip data. Useful if you need to create
* multiple zips with different data.
*
* @return CI_Zip
*/
public function clear_data()
{
$this->zipdata = '';
$this->directory = '';
$this->entries = 0;
$this->file_num = 0;
$this->offset = 0;
return $this;
}
// --------------------------------------------------------------------
/**
* Byte-safe strlen()
*
* @param string $str
* @return int
*/
protected static function strlen($str)
{
return (self::$func_overload)
? mb_strlen($str, '8bit')
: strlen($str);
}
// --------------------------------------------------------------------
/**
* Byte-safe substr()
*
* @param string $str
* @param int $start
* @param int $length
* @return string
*/
protected static function substr($str, $start, $length = NULL)
{
if (self::$func_overload)
{
// mb_substr($str, $start, null, '8bit') returns an empty
// string on PHP 5.3
isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
return mb_substr($str, $start, $length, '8bit');
}
return isset($length)
? substr($str, $start, $length)
: substr($str, $start);
}
}