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; }