function MakeAvatarBackup() { include 'zip.php'; $xlist = array(); //echo mnmpath; $pos = strrpos($_SERVER["SCRIPT_NAME"], "/"); //echo $_SERVER['DOCUMENT_ROOT']; //echo $path = substr($_SERVER["SCRIPT_NAME"], 0, $pos); //echo my_pligg_base."/avatars/"; $files = $this->filelist($_SERVER['DOCUMENT_ROOT'] . my_pligg_base . "/avatars/", 1, 0); // call the function //echo "<pre>"; //print_r($files); foreach ($files as $list) { //print array if ($list['dir'] == 0) { $xlist[] = $list['path'] . $list['name']; } } // Random 5 characters to append to file names to prevent name guessing $rand = substr(md5(microtime()), rand(0, 26), 5); //print_r($xlist); //die("aaa"); // code from http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/ $zipname = 'Avatars' . "_" . date("Y-m-d_H-i-s") . '_' . $rand . '.zip'; $zipfile = new Archive_Zip('./backup/' . $zipname); $p_params = array('remove_path' => $_SERVER['DOCUMENT_ROOT'] . my_pligg_base); $zipfile->create($xlist, $p_params); echo 'Zip file created -- <a href = "' . './backup/' . $zipname . '">' . $zipname . '</a>'; $this->success = 1; }
public function createAction() { //ini_set ( "memory_limit", "256M" ); // Sean Smith: 10/26/2011 - Reworked app packaging to handle multiple // sites calling this function at once $this->init(); // Check for existing site directory, copy package files from code // source location (/app/desktop/distro) to site dir if (!$this->_prepareSiteDirectory()) { // If dir structure not right, or a file copy failed, // bail and render error page (download.phtml) $this->view->assign('error_message', 'Could not create package. The error was: ' . $this->error_message); return; } // Populate sqlite db from mysql db $this->dbAction(); //zip up require_once 'app/desktop/Zip.php'; $file_collection = array(); $zipNameLen = strlen($this->zip_name); unlink($this->package_dir . '/' . $this->zip_name); $archive = new Archive_Zip($this->package_dir . '/' . $this->zip_name); // Gather up all files in distro directory // initialize an iterator pass it the directory to be processed $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Globals::$BASE_PATH . 'app/desktop/distro')); // iterate over the directory add each file found to the archive foreach ($iterator as $key => $value) { // Exclude the zip file itself (if exists from a previous creation) if (substr($key, $zipNameLen * -1, $zipNameLen) != $this->zip_name) { $core_file_collection[] = realpath($key); } } // Gather up the site specific files (data/settings.xml and data/sqlite.db) $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->package_dir)); foreach ($iterator as $key => $value) { // Exclude the zip file itself if (substr($key, $zipNameLen * -1, $zipNameLen) != $this->zip_name) { $site_file_collection[] = realpath($key); } } // Files added in two stages because there are two paths to remove // (app/desktop/distro and package_dir) but zip procs will only take one path to remove per call $archive->create($site_file_collection, array('remove_path' => $this->package_dir, 'add_path' => 'TS')); $archive->add($core_file_collection, array('remove_path' => Globals::$BASE_PATH . 'app/desktop/distro', 'add_path' => 'TS')); }
function MakeAvatarBackup() { include 'zip.php'; $xlist = array(); $files = $this->filelist("./avatars/", 1, 0); // call the function foreach ($files as $list) { //print array if ($list['dir'] == 0) { $xlist[] = $list['path'] . $list['name']; } } // code from http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/ $zipname = 'AvatarBackup' . "-" . date("Y-m-d H-i-s") . '.zip'; $zipfile = new Archive_Zip('./backup/' . $zipname); $zipfile->create($xlist); echo 'Zip file created -- <a href = "' . './backup/' . $zipname . '">' . $zipname . '</a>'; $this->success = 1; }
/** * Send a bunch of files or directories as an archive * * Example: * <code> * require_once 'HTTP/Download/Archive.php'; * HTTP_Download_Archive::send( * 'myArchive.tgz', * '/var/ftp/pub/mike', * HTTP_DOWNLOAD_BZ2, * '', * '/var/ftp/pub' * ); * </code> * * @see Archive_Tar::createModify() * @static * @access public * @return mixed Returns true on success or PEAR_Error on failure. * @param string $name name the sent archive should have * @param mixed $files files/directories * @param string $type archive type * @param string $add_path path that should be prepended to the files * @param string $strip_path path that should be stripped from the files */ static function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_path = '') { $tmp = System::mktemp(); switch ($type = strToUpper($type)) { case HTTP_DOWNLOAD_TAR: include_once 'Archive/Tar.php'; $arc = new Archive_Tar($tmp); $content_type = 'x-tar'; break; case HTTP_DOWNLOAD_TGZ: include_once 'Archive/Tar.php'; $arc = new Archive_Tar($tmp, 'gz'); $content_type = 'x-gzip'; break; case HTTP_DOWNLOAD_BZ2: include_once 'Archive/Tar.php'; $arc = new Archive_Tar($tmp, 'bz2'); $content_type = 'x-bzip2'; break; case HTTP_DOWNLOAD_ZIP: include_once 'Archive/Zip.php'; $arc = new Archive_Zip($tmp); $content_type = 'x-zip'; break; default: return PEAR::raiseError('Archive type not supported: ' . $type, HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE); } if ($type == HTTP_DOWNLOAD_ZIP) { $options = array('add_path' => $add_path, 'remove_path' => $strip_path); if (!$arc->create($files, $options)) { return PEAR::raiseError('Archive creation failed.'); } } else { if (!($e = $arc->createModify($files, $add_path, $strip_path))) { return PEAR::raiseError('Archive creation failed.'); } if (PEAR::isError($e)) { return $e; } } unset($arc); $dl = new HTTP_Download(array('file' => $tmp)); $dl->setContentType('application/' . $content_type); $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name); return $dl->send(); }
unlink($local_file); } // write $render to file if (!file_put_contents($local_file, $renderMMO)) { echo "could not write to file - {$local_file}"; exit; } // add xml to files array $filesToDelete[] = $local_file; // write all images and xml file to zip include 'Archive/Zip.php'; // imports $obj = new Archive_Zip($strPath . "/" . $strZipFile); // name of zip file $files = $filesToDelete; if ($obj->create($files, array('remove_all_path' => 1))) { } else { $errors[] = 'Error in zip file creation'; } // delete all files no longer required foreach ($filesToDelete as $filename) { @unlink($filename); } /* FTP Username = pppmgold FTP Password = kw4djr0x FTP Hostname = uploads.fish4.co.uk */ //$ftp_server = "uploads.fish4.co.uk"; //$ftp_username = "******"; //$ftp_password = "******";
function zip($aszSource, $szDestination) { // include file include_once COMMON . "/zip/zip.php"; // build archive $szDirName = dirname($szDestination); // specify filename for output file $aParams = array(); $aParams[ARCHIVE_ZIP_PARAM_REMOVE_ALL_PATH] = true; $zip = new Archive_Zip($szDestination); if (!$zip->create($aszSource, $aParams)) { return false; } else { return true; } }
<?php include 'Archive/Zip.php'; // imports $obj = new Archive_Zip('test.zip'); // name of zip file $files = array('client2area.php', 'edit_property.php', 'find_property_orphan.php'); // files to store if ($obj->create($files)) { echo 'Created successfully!'; } else { echo 'Error in file creation'; }