Exemplo n.º 1
0
 /**
  *  Compress file as zip using pclzip library (thanhnv - use other lib now :D)
  *
  * @param $zipFile  string path to store zip file
  * @param $path {string | array()} path to file or directory to zip
  * @param $rmPath  boolean do not add full path to archive
  *
  * @return  boolean true if success, false if failure
  */
 function zip($zipFile, $path, $rmPath = false)
 {
     $oZip = new CreateZipFile();
     if (!is_array($path)) {
         $paths[] = $path;
     } else {
         $paths = $path;
     }
     foreach ($paths as $path) {
         if (JFile::exists($path)) {
             $oZip->addDirectory($outputDir);
             $fileContents = file_get_contents($path);
             $oZip->addFile($fileContents, basename($path));
         } elseif (JFolder::exists($path)) {
             $outputDir = str_replace(array(dirname($path), DS, '/'), '', $path) . DS;
             $oZip->zipDirectory($path, $outputDir);
         }
     }
     $out = JFile::write($zipFile, $oZip->getZippedfile());
     return $out;
 }
Exemplo n.º 2
0
 /**
  *  Compress file as zip using pclzip library (thanhnv - use other lib now :D)
  *
  * @param $zipFile  string path to store zip file
  * @param $path {string | array()} path to file or directory to zip
  * @param $rmPath  boolean do not add full path to archive
  *
  * @return  boolean true if success, false if failure
  */
 public static function zip($zipFile, $path, $rmPath = false)
 {
     $oZip = new CreateZipFile();
     if (!is_array($path)) {
         $paths[] = $path;
     } else {
         $paths = $path;
     }
     foreach ($paths as $path) {
         if (is_file($path)) {
             $oZip->addDirectory($outputDir);
             $fileContents = file_get_contents($path);
             $oZip->addFile($fileContents, basename($path));
         } elseif (is_dir($path)) {
             $outputDir = str_replace(array(dirname($path), DS, '/'), '', $path) . DS;
             $oZip->zipDirectory($path, $outputDir);
         }
     }
     $fp = fopen($zipFile, "wb");
     $out = fwrite($fp, $oZip->getZippedfile());
     fclose($fp);
     return $out;
 }
 function export_xliff()
 {
     global $wpdb, $current_user;
     get_currentuserinfo();
     $data = $_GET['xliff_export_data'];
     $data = unserialize(base64_decode($data));
     //by default set xliff version to 1.2
     $xliff_version = '1.2';
     //check for required xliff version from action name
     if (isset($data['action2'])) {
         $xliff_action = $data['action2'];
         //we are looking for action in format: export_xliff_VERSION
         if (strpos($xliff_action, 'export_xliff_') === 0) {
             switch (ltrim($xliff_action, 'export_xliff_')) {
                 case '10':
                     $xliff_version = '1.0';
                     break;
                 case '11':
                     $xliff_version = '1.1';
                     break;
                 case '12':
                     $xliff_version = '1.2';
                     break;
             }
         }
     }
     require_once WPML_XLIFF_PATH . '/inc/CreateZipFile.inc.php';
     $archive = new CreateZipFile();
     $job_ids = array();
     foreach ($data['job'] as $job_id => $dummy) {
         $xliff_file = $this->get_xliff_file($job_id, $xliff_version);
         // assign the job to this translator
         $rid = $wpdb->get_var("SELECT rid FROM {$wpdb->prefix}icl_translate_job WHERE job_id={$job_id}");
         $wpdb->update($wpdb->prefix . 'icl_translate_job', array('translator_id' => $current_user->ID), array('job_id' => $job_id));
         $wpdb->update($wpdb->prefix . 'icl_translation_status', array('translator_id' => $current_user->ID), array('rid' => $rid));
         $archive->addFile($xliff_file, get_bloginfo('name') . '-translation-job-' . $job_id . '.xliff');
         $job_ids[] = $job_id;
     }
     $archive_data = $archive->getZippedfile();
     header("Content-Type: application/force-download");
     header("Content-Type: application/octet-stream");
     header("Content-Type: application/download");
     header("Content-Disposition: attachment; filename=" . $this->_get_zip_name_from_jobs($job_ids));
     //header("Content-Encoding: gzip");
     header("Content-Length: " . strlen($archive_data));
     echo $archive_data;
     exit;
 }
Exemplo n.º 4
0
<?php

$fileToZip = "License.txt";
$fileToZip1 = "CreateZipFileMac.inc.php";
$fileToZip2 = "CreateZipFile.inc.php";
$directoryToZip = "./";
// This will zip all the file(s) in this present working directory
$outputDir = "/";
//Replace "/" with the name of the desired output directory.
$zipName = "test.zip";
include_once "CreateZipFile.inc.php";
$createZipFile = new CreateZipFile();
/*
// Code to Zip a single file
$createZipFile->addDirectory($outputDir);
$fileContents=file_get_contents($fileToZip);
$createZipFile->addFile($fileContents, $outputDir.$fileToZip);
*/
//Code toZip a directory and all its files/subdirectories
$createZipFile->zipDirectory($directoryToZip, $outputDir);
$rand = md5(microtime() . rand(0, 999999));
$zipName = $rand . "_" . $zipName;
$fd = fopen($zipName, "wb");
$out = fwrite($fd, $createZipFile->getZippedfile());
fclose($fd);
$createZipFile->forceDownload($zipName);
@unlink($zipName);
Exemplo n.º 5
0
 function admin_export($id = null)
 {
     if (!$id) {
         $this->Session->setFlash(__('Please select a template', true));
         $this->redirect($this->referer());
     }
     $this->Template->recursive = -1;
     $template = $this->Template->read(array('name', 'description', 'author', 'header', 'footer'), $id);
     if (empty($template)) {
         $this->Session->setFlash(__('The template does not exist.', true));
         $this->redirect($this->referer());
     }
     $pattern = "/src=[\\\"']?([^\\\"']?.*(png|jpg|gif|jpeg))[\\\"']?/i";
     preg_match_all($pattern, $template['Template']['header'], $images);
     $path = TMP . 'cache' . DS . 'newsletter' . DS . 'template' . DS . $template['Template']['name'];
     $Folder = new Folder($path, 0777);
     $slash = $Folder->correctSlashFor($path);
     App::import('File');
     App::import('Folder');
     $File = new File($path . DS . 'template.xml', true, 0777);
     $image_files = array();
     if (!empty($images[1])) {
         foreach ($images[1] as $img) {
             $img = str_replace('/', $slash, $img);
             $img = str_replace('\\', $slash . $slash, $img);
             $image_files[] = $img;
             if (is_file(APP . 'webroot' . $img)) {
                 $Folder->create(dirname($path . $img), 0777);
                 $File->path = APP . 'webroot' . $img;
                 $File->copy(dirname($path . $img) . DS . basename($img));
             }
         }
     }
     $xml['template']['name'] = 'Infinitas Newsletter Template';
     $xml['template']['generator'] = 'Infinitas Template Generator';
     $xml['template']['version'] = $this->version;
     $xml['template']['template'] = $template['Template']['name'];
     $xml['template']['description'] = $template['Template']['description'];
     $xml['template']['author'] = $template['Template']['author'];
     $xml['data']['header'] = $template['Template']['header'];
     $xml['data']['footer'] = $template['Template']['footer'];
     $xml['files']['images'] = $image_files;
     App::Import('Helper', 'Xml');
     $Xml = new XmlHelper();
     $xml_string = $Xml->serialize($xml);
     $File->path = $path . DS . 'template.xml';
     $File->write($xml_string);
     App::import('Vendor', 'Zip', array('file' => 'zip.php'));
     $Zip = new CreateZipFile();
     $Zip->zipDirectory($path, null);
     $File = new File($path . DS . 'template.zip', true, 0777);
     $File->write($Zip->getZippedfile());
     $this->view = 'Media';
     $params = array('id' => 'template.zip', 'name' => $template['Template']['name'], 'download' => true, 'extension' => 'zip', 'path' => $path . DS);
     $this->set($params);
     $Folder = new Folder($path);
     $Folder->read();
     $Folder->delete($path);
 }
Exemplo n.º 6
0
            rmdir($dir_wpath);
        } else {
            foreach (get_files($dir_wpath) as $f) {
                if (file_exists($backup_wpath)) {
                    unlink($dir_wpath . '/' . $f);
                } else {
                    $outputDir = "backup/";
                    //Replace "/" with the name of the desired output directory.
                    $zipName = "backup_" . date('Ymd_His') . ".zip";
                    $zip = new CreateZipFile();
                    //Code toZip a directory and all its files/subdirectories
                    $zip->zipDirectory("upload");
                    $rand = md5(microtime() . rand(0, 999999));
                    $backup_wpath = $outputDir . $zipName;
                    $fd = fopen($backup_wpath, "wb");
                    $out = fwrite($fd, $zip->getZippedfile());
                    fclose($fd);
                    #$zip->addFile($dir_wpath, $f);
                    #$zip->save($backup_wpath);
                }
            }
        }
    }
    $i++;
}
/**
 * Get all files in directory
 *
 * @param string $path 
 * @return array
 * @author Andrew Smith