$str_applilcation = str_replace("[package_name]", $package_name, $str_applilcation); $str_applilcation = str_replace("[package_service]", $package_service, $str_applilcation); $str_applilcation = str_replace("[package_price]", $package_price, $str_applilcation); $str_applilcation = str_replace("[script_refund_policy]", $script_refund_policy, $str_applilcation); $str_applilcation = str_replace("[package_description]", $package_description, $str_applilcation); } $str_applilcation = str_replace("[company_bank]", $company_bank, $str_applilcation); $str_applilcation = str_replace("[beneficiary_name]", $beneficiary_name, $str_applilcation); $str_applilcation = str_replace("[name_on_account]", $name_on_account, $str_applilcation); $str_applilcation = str_replace("[bank_address]", $bank_address, $str_applilcation); $str_applilcation = str_replace("[bank_country]", $bank_country, $str_applilcation); $str_applilcation = str_replace("[bank_phone]", $bank_phone, $str_applilcation); $str_applilcation = str_replace("[bank_sort_code]", $bank_sort_code, $str_applilcation); $str_applilcation = str_replace("[bank_account_number]", $bank_account_number, $str_applilcation); $str_applilcation = str_replace("[bank_swift_code]", $bank_swift_code, $str_applilcation); $zipfile->add_dir($dir_company_name . "/"); //$zipfile -> add_dir($dir_company_name."/Application/"); $filedata = $str_applilcation; $zipfile->add_file($filedata, $dir_company_name . "/" . $str_company_name . ".html"); } //print("comp. file size= ".$zipfile -> get_file_size()."<br>"); // print($str_company_name."<br>"); if ($is_doc != "") { $myLicenceFileArray = array(); $myArticlesFileArray = array(); $myHistoryFileArray = array(); $myProfessionalReferenceFileArray = array(); //$str_qry = "select file_type, file_name from cs_uploaded_documents where user_id = $company_id and status = 'A'"; $str_qry = "select file_type, file_name from cs_uploaded_documents where status='A' AND user_id = {$company_id}"; if (!($show_sql = mysql_query($str_qry, $cnn_cs))) { print mysql_errno() . ": " . mysql_error() . "<BR>";
function process_backup($user) { include_once "class_zip.php"; if ($_REQUEST['choice'] == 'yes') { //CREATE A UNIX TIMESTAMP $stamp = time(); $date1 = gmdate("m-d-y", $stamp); $date = gmdate("Y-m-d H:i:s", $stamp); $title = "bu_" . $date . "_" . $user->user_name . ".zip"; //CREATE THE BACKUP OF OUR DATABASE $filename = "../" . $this->config->file_dir . "/tmp_{$date1}.sql"; passthru("mysqldump --opt -h" . $this->config->db_host . " -u" . $this->config->db_user . " -p" . $this->config->db_pass . " " . $this->config->db_name . " >{$filename}"); // $zipfile = new zipfile(); //READ THE CURRENT DIRECTORY WE ARE IN $dir_list = $this->read_dir("../"); for ($i = 0; $i < count($dir_list); $i++) { if ($dir_list[$i]['type'] == "dir") { //echo $dir_list[$i]['name']."<br/>"; $zipfile->add_dir($dir_list[$i]['name']); } else { if ($dir_list[$i]['type'] == "file") { //echo $dir_list[$i]['name']."<br/>"; $zipfile->add_file(file_get_contents($dir_list[$i]['loc'], false), $dir_list[$i]['name']); } } } //REMOVE OUR TEMP SQL FILE unlink($filename); //CREATE THE SYSTEM NAME $sql = "SELECT id FROM " . $this->config->db_prefix . "_files ORDER BY id DESC"; $results = $this->db->DB_Q_C($sql); $total_files = mysql_fetch_array($results); $total_files[0]++; $sys_name = "file_" . $total_files[0] . ".zip"; //CREATE THE ZIP FILE $fileName = "../" . $this->config->file_dir . "/backup/{$sys_name}"; $fd = fopen($fileName, "w"); $out = fwrite($fd, $zipfile->file()); fclose($fd); // $sql = "INSERT INTO `" . $this->config->db_prefix . "_files` VALUES ('', '{$title}', '{$sys_name}', '../" . $this->config->file_dir . "/backup/', 'zip', 'A backup of your site.')"; $results = $this->db->DB_Q_C($sql); $lastid = mysql_insert_id(); //LOG THE ACTION $sql = "INSERT INTO " . $this->config->db_prefix . "_object(create_date, create_who) \r\r\n \t\t\t VALUES('{$date}', '{$user->user_id}')"; $results = $this->db->DB_Q_C($sql); $lastobjectid = mysql_insert_id(); $sql = "INSERT INTO " . $this->config->db_prefix . "_logs(object_id, user_id, module_id, sub_module_id, record_id, action)\r\r\n VALUES({$lastobjectid}, '" . $user->user_id . "', '" . $this->id . "', 1, {$lastid}, 1)"; $results = $this->db->DB_Q_C($sql); // $ret_code = array(1, $lastid); } else { $ret_code = array(-1, 0); } return $ret_code; }
function export_theme($theme_dir) { require AT_INCLUDE_PATH . 'classes/zipfile.class.php'; /* for zipfile */ require AT_INCLUDE_PATH . 'classes/XML/XML_HTMLSax/XML_HTMLSax.php'; /* for XML_HTMLSax */ require 'theme_template.inc.php'; /* for theme XML templates */ global $db; //identify current theme and then searches db for relavent info $sql = "SELECT * FROM " . TABLE_PREFIX . "themes WHERE dir_name = '{$theme_dir}'"; $result = mysql_query($sql, $db); $row = mysql_fetch_assoc($result); $dir = $row['dir_name'] . '/'; $title = $row['title']; $version = $row['version']; $type = $row['type']; $last_updated = $row['last_updated']; $extra_info = $row['extra_info']; //generate 'theme_info.xml' file based on info $info_xml = str_replace(array('{TITLE}', '{VERSION}', '{TYPE}', '{LAST_UPDATED}', '{EXTRA_INFO}'), array($title, $version, $type, $last_updated, $extra_info), $theme_template_xml); //zip together all the contents of the folder along with the XML file $zipfile = new zipfile(); $zipfile->create_dir($dir); //update installation folder $dir1 = get_main_theme_dir(intval($row["customized"])) . $dir; $zipfile->add_file($info_xml, $dir . 'theme_info.xml'); /* zip other required files */ $zipfile->add_dir($dir1, $dir); /*close & send*/ $zipfile->close(); //Name the Zip file and sends to user for download $zipfile->send_file(str_replace(array(' ', ':'), '_', $title)); }
$module = $moduleFactory->getModule($_GET['mod_dir']); $main_module_dir = $module->getModulePath(); $module_folder = $main_module_dir . $_GET['mod_dir']; // check if the module has been un-installed if (!file_exists($module_folder)) { $msg->addError('ITEM_NOT_FOUND'); } // only extra modules can be uninstalled if (!$module->isExtra()) { $msg->addError('ONLY_EXPORT_EXTRA_MODULE'); } if (!$msg->containsErrors()) { require AT_INCLUDE_PATH . 'classes/zipfile.class.php'; /* for zipfile */ $zipfile = new zipfile(); $zipfile->add_dir($main_module_dir . $_GET['mod_dir'] . '/', $_GET['mod_dir'] . '/'); $zipfile->close(); $zipfile->send_file($_GET['mod_dir']); exit; } } else { if (isset($_GET['disable']) || isset($_GET['enable']) || isset($_GET['details']) || isset($_GET['uninstall']) || isset($_GET['export'])) { $msg->addError('NO_ITEM_SELECTED'); header('Location: ' . $_SERVER['PHP_SELF'] . '?' . $args); exit; } } } } } }
$load['plugin'] = true; // Relative $relative = '../'; // Include common.php include 'inc/common.php'; // check validity of request if ($_REQUEST['s'] === $SESSIONHASH) { require_once 'inc/zip.class.php'; $zipfile = new zipfile(); $timestamp = date('Y-m-d-Hi'); ini_set("memory_limit", "600M"); // paths and files to backup $paths = array($relative . 'data', $relative . 'theme'); //no trailing slash $files = array($relative . '.htaccess', $relative . 'index.php', $relative . 'gsconfig.php'); $zipfile->add_dir('getsimple'); // cycle thru each path and file and add to zip file foreach ($paths as $path) { $dir_handle = @opendir($path) or die("Unable to open {$path}"); ListDir($dir_handle, $path); } foreach ($files as $fl) { $filedata = file_get_contents($fl); $zipfile->add_file($filedata, substr_replace($fl, 'getsimple', 0, 2)); } // $listing is the list of all files and folders that were added to the backup //echo $listing; // create the final zip file $file = $relative . 'backups/zip/' . $timestamp . '_archive.zip'; $fh = fopen($file, 'w') or die('Could not open file for writing!'); fwrite($fh, $zipfile->file()) or die('Could not write to file');
if (!file_exists($module_folder)) { $msg->addError('ITEM_NOT_FOUND'); } // only extra modules can be uninstalled if (!$module->isExtra()) { $msg->addError('ONLY_EXPORT_EXTRA_MODULE'); } if (!$msg->containsErrors()) { require(AT_INCLUDE_PATH.'classes/zipfile.class.php'); /* for zipfile */ $zipfile = new zipfile(); $zipfile->add_dir('../../../mods/'.$_GET['mod_dir'].'/', $_GET['mod_dir'].'/'); $zipfile->close(); $zipfile->send_file($_GET['mod_dir']); exit; } } else if (isset($_GET['disable']) || isset($_GET['enable']) || isset($_GET['details']) || isset($_GET['uninstall']) || isset($_GET['export'])) { $msg->addError('NO_ITEM_SELECTED'); header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args); exit; } require(AT_INCLUDE_PATH.'header.inc.php'); $module_status_bits = $module_type_bits = 0;
// 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)) . pack("v", sizeof($this->ctrl_dir)) . pack("V", strlen($ctrldir)) . pack("V", strlen($data)) . ""; // .zip file comment length } } ?> Example Usage of the Class <?php $zipfile = new zipfile(); // add the subdirectory ... important! $zipfile->add_dir("test/"); // add the binary data stored in the string 'filedata' //$filename = "c:\\apache\\apache\\htdocs\\projects\\companysetup\\admin\\5_SREEnew.doc"; $filename = "c:\\apache\\apache\\htdocs\\projects\\companysetup\\admin\\passports.jpg"; $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); fclose($handle); $filedata = $contents; $zipfile->add_file($filedata, "test/passports.jpg"); // the next three lines force an immediate download of the zip file: //header("Content-type: application/octet-stream"); //header("Content-disposition: attachment; filename=test.zip"); //echo $zipfile -> file(); // OR instead of doing that, you can write out the file to the loca disk like this: $filename = "output.zip"; $fd = fopen($filename, "wb");
function getModel($originalPath) { $sourcePath = $originalPath; $filePath = str_ireplace(DCTL_PROJECT_PATH, '', $sourcePath); $zip = new zipfile(); $zipdir = SYS_PATH_SEP; $zip->add_dir($zipdir); addToZip(DCTL_SETTINGS, $zip, $zipdir); $zipdir = SYS_PATH_SEP; $source = DCTL_PROJECT_PATH; foreach (explode(SYS_PATH_SEP, $filePath) as $item) { $source .= $item; $zipdir .= $item; if (is_dir($source)) { $source .= SYS_PATH_SEP; $zipdir .= SYS_PATH_SEP; $zip->add_dir($zipdir); $item = $source . DCTL_FILE_HEADER; if (is_file($item)) { addToZip($item, $zip, $zipdir); } // $item = $source.DCTL_MEDIA_SML; // if (is_dir($item)) { // addToZip($item, $zip, $zipdir); // }; } } $zipdir = dirname($zipdir) . SYS_PATH_SEP; if (is_dir($source)) { if (stripos(DCTL_MEDIA_SML, $source) === FALSE && stripos(DCTL_MEDIA_MED, $source) === FALSE) { addToZip($source, $zip, $zipdir); } } else { if (is_file($source)) { $item = $source; addToZip($item, $zip, $zipdir); } } $filePath = dirname($originalPath) . SYS_PATH_SEP . str_ireplace(SYS_PATH_SEP, '#', $filePath) . '.zip'; $fd = fopen($filePath, "wb"); $out = fwrite($fd, $zip->file()); fclose($fd); @chmod($filePath, CHMOD); return $filePath; }
if ($i_loop == 0) { $zipfile->add_dir($dir_company_name . "/License/"); } } $zipfile->add_file($filedata, $dir_company_name . "/License/" . $myLicenceFileArray[$i_loop]); } //print("comp. file size= ".$zipfile -> get_file_size()."<br>"); } if (count($myProfessionalReferenceFileArray) > 0) { for ($i_loop = 0; $i_loop < count($myProfessionalReferenceFileArray); $i_loop++) { $filedata = func_read_file("../gateway/" . $_SESSION['gw_folder'] . "UserDocuments/Professional_Reference/" . $myProfessionalReferenceFileArray[$i_loop]); $compressed_file_size = func_get_compressed_file_size($filedata); if ($zipfile->get_file_size() + $compressed_file_size >= $i_max_file_size_MB) { $arr_result = func_send_documents($zipfile, $str_company_name, $other_email, $str_failure_companies, $i_max_file_size_MB, $error_msg); $zipfile = new zipfile(); $zipfile->add_dir($dir_company_name . "/Professional_Reference/"); } else { if ($i_loop == 0) { $zipfile->add_dir($dir_company_name . "/Professional_Reference/"); } } $zipfile->add_file($filedata, $dir_company_name . "/Professional_Reference/" . $myProfessionalReferenceFileArray[$i_loop]); } //print("comp. file size= ".$zipfile -> get_file_size()."<br>"); } } if ($zipfile->get_file_size() > 0) { $arr_result = func_send_documents($zipfile, $str_company_name, $other_email, $str_failure_companies, $i_max_file_size_MB, $error_msg); } } function getDirList($dirName, $i_company)
$str_applilcation = str_replace("[transaction_fee]", $transaction_fee, $str_applilcation); $str_applilcation = str_replace("[voice_authorization_fee]", $voice_authorization_fee, $str_applilcation); $str_applilcation = str_replace("[discount_rate]", $discount_rate, $str_applilcation); $str_applilcation = str_replace("[reserve]", $reserve, $str_applilcation); $str_applilcation = str_replace("[company_status]", $company_status, $str_applilcation); $str_applilcation = str_replace("[merchant_type]", $merchant_type, $str_applilcation); $str_applilcation = str_replace("[volumenumber]", $volumenumber, $str_applilcation); $str_applilcation = str_replace("[avgticket]", $avgticket, $str_applilcation); $str_applilcation = str_replace("[company_bank]", $company_bank, $str_applilcation); $str_applilcation = str_replace("[bank_address]", $bank_address, $str_applilcation); $str_applilcation = str_replace("[bank_country]", $bank_country, $str_applilcation); $str_applilcation = str_replace("[bank_phone]", $bank_phone, $str_applilcation); $str_applilcation = str_replace("[bank_sort_code]", $bank_sort_code, $str_applilcation); $str_applilcation = str_replace("[bank_account_number]", $bank_account_number, $str_applilcation); $str_applilcation = str_replace("[bank_swift_code]", $bank_swift_code, $str_applilcation); $zipfile->add_dir($dir_company_name . "/"); $zipfile->add_dir($dir_company_name . "/Application/"); $filedata = $str_applilcation; $zipfile->add_file($filedata, $dir_company_name . "/Application/application_" . $company_id . ".html"); } //print("comp. file size= ".$zipfile -> get_file_size()."<br>"); // print($str_company_name."<br>"); if ($is_doc != "") { $myLicenceFileArray = array(); $myArticlesFileArray = array(); $myHistoryFileArray = array(); $myProfessionalReferenceFileArray = array(); $str_qry = "select file_type, file_name from cs_uploaded_documents where user_id = {$company_id} and status = 'A'"; if (!($show_sql = mysql_query($str_qry, $cnn_cs))) { print mysql_errno() . ": " . mysql_error() . "<BR>"; print "Cannot execute query";