Esempio n. 1
0
 public function admin_export($id = null)
 {
     if (!$id) {
         $this->notice('invalid');
     }
     $this->Template->recursive = -1;
     $template = $this->Template->read(array('name', 'description', 'author', 'header', 'footer'), $id);
     if (empty($template)) {
         $this->notice('invalid');
     }
     $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);
     $imageFiles = array();
     if (!empty($images[1])) {
         foreach ($images[1] as $img) {
             $img = str_replace('/', $slash, $img);
             $img = str_replace('\\', $slash . $slash, $img);
             $imageFiles[] = $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'] = $imageFiles;
     App::Import('Helper', 'Xml');
     $Xml = new XmlHelper();
     $File->path = $path . DS . 'template.xml';
     $File->write($Xml->serialize($xml));
     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);
 }
Esempio 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
  */
 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;
 }
 /**
  *  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;
 }
Esempio n. 5
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);
Esempio n. 6
0
// Sollen Dateinnamen im Zip die Pfade beinhalten?
if ($_GET['incp'] == 'y') {
    $incp = true;
} else {
    $incp = false;
}
$outputDir = "/";
//Replace "/" with the name of the desired output directory.
$path_array = explode("/", $directoryToZip);
$zipName = $path_array[count($path_array) - 2];
$rand = md5(microtime() . rand(0, 999999));
$zipName = $zipName . "_" . $rand . ".zip";
include_once "./include/functions.php";
include_once "./include/zipbuilder.php";
//include_once("./include/zip_withfile.php");
$createZipFile = new CreateZipFile(true);
/* 
// 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, $zipName);
//$createZipFile->zipDirectory($directoryToZip,$outputDir);
//$createZipFile->sendZip($zipName);
$createZipFile->forceDownload($zipName);
unlink($zipName);
//$fd=fopen($zipName, "wb");
//$out=fwrite($fd,$createZipFile->getZippedfile());
//fclose($fd);
<?php

if (isset($_REQUEST['File']) && !empty($_REQUEST['File'])) {
    define('WP_USE_THEMES', false);
    require '../../../wp-load.php';
    require "create_zip_file.php";
    $uploads = wp_upload_dir();
    $tmp_location = $uploads['path'] . "/" . $_REQUEST['File'];
    //echo $tmp_location;
    $zip = new CreateZipFile();
    $zip->forceDownload($tmp_location, false);
    unlink($tmp_location);
    exit;
}
 public function actionBackup()
 {
     Yii::import('application.extensions.yii-zip.CreateZipFile');
     $createZip = new CreateZipFile();
     //$createZip->zipDirectory('../ims/protected', '');
     $createZip->zipDirectory('protected/data', '');
     $date = date('d-F-y-h-i');
     $zipFileName = $date . '_ims_backup.zip';
     $handle = fopen($zipFileName, 'wb');
     $out = fwrite($handle, $createZip->getZippedFile());
     fclose($handle);
     $createZip->forceDownload($zipFileName);
     @unlink($zipFileName);
 }
 function download_zip()
 {
     require "create_zip_file.php";
     $files_to_zip = array();
     // create files array
     //run a query
     $post_id = $_POST["Id"];
     $args = array('post_type' => $this->post_types_attachments, 'post_parent' => $post_id);
     $attachments = get_posts($args);
     if ($attachments) {
         //print_r($attachments);
         foreach ($attachments as $attachment) {
             $files_to_zip[] = get_attached_file($attachment->ID);
             // populate files array
         }
         //print_r($files_to_zip);
         //exit;
         $zip = new CreateZipFile();
         $uploads = wp_upload_dir();
         $tmp_location = $uploads['path'];
         $tmp_location_url = $uploads['url'];
         $FileName = sanitize_title(get_the_title($post_id)) . ".zip";
         $zipFileName = $tmp_location . '/' . $FileName;
         //$zipFileName_url = $tmp_location_url.'/'.sanitize_title(get_the_title($post_id)).".zip";
         //$zip->addDirectory('/');
         foreach ($files_to_zip as $file) {
             //$filecontent =
             $zip->addFile(file_get_contents($file), basename($file));
         }
         $handle = fopen($zipFileName, 'wb');
         $out = fwrite($handle, $zip->getZippedFile());
         fclose($handle);
         //$zip->forceDownload($zipFileName);
         //@unlink($zipFileName);
         echo plugins_url($file_path, __FILE__) . "/download.php?File=" . $FileName;
     } else {
         echo 'false';
     }
     exit;
 }
Esempio n. 10
0
$dir = get_files($usr_path);
$i = 0;
while ($i < count($dir)) {
    foreach ($dir as $d) {
        $dir_wpath = $usr_path . $d;
        if (is_empty($dir_wpath)) {
            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++;
}