ZipArchive PHP Class Code Examples

This page contains top rated real world PHP examples of class ZipArchive extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: Feed_DOVE.class.php Project: arribanz/live
0
 public function download_feeds()
 {
     global $logger;
     return true;
     $filetxt = FEED_PATH . "synnex.csv";
     $file2 = FEED_PATH . "/feedssynnex.csv.txt.zip";
     $fdiff = (date("U") - @filemtime($filetxt)) / 3600;
     if ($fdiff > 4) {
         $zip = new ZipArchive();
         $res = $zip->open($file2);
         if ($res === TRUE) {
             $zip->extractTo(FEED_PATH . "/");
             $zip->close();
         } else {
             echo "error during unzip process";
         }
     }
     return true;
     $cont = file_get_contents("");
     file_put_contents($file, $cont);
     $logger->LogCron("DATAFEED DOWNLOADED (" . ImpLib::convert(filesize($file)) . ")");
     $zip = new ZipArchive();
     $res = $zip->open($file);
     if ($res === TRUE) {
         $zip->extractTo(FEED_PATH . "/" . $this->name . "/");
         $zip->close();
     } else {
         echo "error during unzip process";
     }
     return true;
 }
Example #2
Show file File: OssnThemes.php Project: nongdanit-nongdanit/ossn
0
 /**
  * Upload component
  *
  * Requires component package file,
  *
  * @return boolean
  */
 public function upload()
 {
     $archive = new ZipArchive();
     $data_dir = ossn_get_userdata('tmp/themes');
     if (!is_dir($data_dir)) {
         mkdir($data_dir, 0755, true);
     }
     $file = new OssnFile();
     $file->setFile('theme_file');
     $file->setExtension(array('zip'));
     $zip = $file->file;
     $newfile = "{$data_dir}/{$zip['name']}";
     if (move_uploaded_file($zip['tmp_name'], $newfile)) {
         if ($archive->open($newfile) === TRUE) {
             $archive->extractTo($data_dir);
             $archive->close();
             $validate = pathinfo($zip['name'], PATHINFO_FILENAME);
             if (is_file("{$data_dir}/{$validate}/ossn_theme.php") && is_file("{$data_dir}/{$validate}/ossn_theme.xml")) {
                 $archive->open($newfile);
                 $archive->extractTo(ossn_route()->themes);
                 $archive->close();
                 OssnFile::DeleteDir($data_dir);
                 return true;
             }
         }
     }
     return false;
 }
Example #3
Show file File: template.php Project: brenot/forumdesenvolvimento
0
 /**
  * Extract contents of a archive file.
  *
  * @param   string  $file  The name and location of the file
  *
  * @return  boolean  true if image extraction is successful, false otherwise.
  *
  * @since   3.2
  */
 public function extractArchive($file)
 {
     if ($template = $this->getTemplate()) {
         $app = JFactory::getApplication();
         $client = JApplicationHelper::getClientInfo($template->client_id);
         $relPath = base64_decode($file);
         $explodeArray = explode('/', $relPath);
         $fileName = end($explodeArray);
         $folderPath = stristr($relPath, $fileName, true);
         $path = JPath::clean($client->path . '/templates/' . $template->element . '/' . $folderPath . '/');
         if (file_exists(JPath::clean($path . '/' . $fileName))) {
             $zip = new ZipArchive();
             if ($zip->open(JPath::clean($path . '/' . $fileName)) === true) {
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $entry = $zip->getNameIndex($i);
                     if (file_exists(JPath::clean($path . '/' . $entry))) {
                         $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_ARCHIVE_EXISTS'), 'error');
                         return false;
                     }
                 }
                 $zip->extractTo($path);
                 return true;
             } else {
                 $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_ARCHIVE_OPEN_FAIL'), 'error');
                 return false;
             }
         } else {
             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_ARCHIVE_NOT_FOUND'), 'error');
             return false;
         }
     }
 }
Example #4
Show file File: UploadHandler.php Project: RA2WP/RA2WP
0
 protected function handle_zip_file($file_path, $file)
 {
     $zip = new ZipArchive();
     $res = $zip->open($file_path);
     if ($res === TRUE) {
         $allow_extract = true;
         for ($i = 0; $i < $zip->numFiles; $i++) {
             $OnlyFileName = $zip->getNameIndex($i);
             $FullFileName = $zip->statIndex($i);
             if (!($FullFileName['name'][strlen($FullFileName['name']) - 1] == "/")) {
                 if (!preg_match('#\\.(gif|jpe?g|png|bmp|mp4|flv|webm|ogg|mp3|wav|pdf|ini|txt)$#i', $OnlyFileName)) {
                     $allow_extract = false;
                 }
             }
         }
         if ($allow_extract) {
             $target_dir = substr($file_path, 0, strlen($file_path) - 4);
             if (!is_dir($target_dir)) {
                 mkdir($target_dir, 0777);
             }
             $zip->extractTo($target_dir);
         } else {
             $file->error = 'Zip file should contain only image files.';
         }
         $zip->close();
         if ($allow_extract) {
             $this->handle_directory($target_dir);
         }
     }
 }
Example #5
Show file File: ExportFormat.php Project: kidaa30/yes
0
 /**
  * @param array $files
  * @param null $destination
  * @param bool $overwrite
  *
  * @return bool
  */
 public function createZip($files = array(), $destination = NULL, $overwrite = FALSE)
 {
     //if the zip file already exists and overwrite is false, return false
     if (file_exists($destination) && !$overwrite) {
         return FALSE;
     }
     $valid_files = array();
     if (is_array($files)) {
         foreach ($files as $file) {
             //make sure the file exists
             if (file_exists($file)) {
                 $validFiles[] = $file;
             }
         }
     }
     if (count($validFiles)) {
         $zip = new ZipArchive();
         if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== TRUE) {
             return FALSE;
         }
         foreach ($validFiles as $file) {
             $zip->addFile($file, CRM_Utils_File::cleanFileName(basename($file)));
         }
         $zip->close();
         return file_exists($destination);
     } else {
         return FALSE;
     }
 }
Example #6
Show file File: filemanager.class.php Project: alexyangfox/Filemanager
0
 /**
  * function zipFile.  Creates a zip file from source to destination
  *
  * @param  string $source Source path for zip
  * @param  string $destination Destination path for zip
  * @param  string|boolean $flag OPTIONAL If true includes the folder also
  * @return boolean
  * @link 	 http://stackoverflow.com/questions/17584869/zip-main-folder-with-sub-folder-inside
  */
 public function zipFile($source, $destination, $flag = '')
 {
     if (!extension_loaded('zip') || !file_exists($source)) {
         return false;
     }
     $zip = new ZipArchive();
     if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
         return false;
     }
     $source = str_replace('\\', '/', realpath($source));
     if ($flag) {
         $flag = basename($source) . '/';
         //$zip->addEmptyDir(basename($source) . '/');
     }
     if (is_dir($source) === true) {
         // add file to prevent empty archive error on download
         $zip->addFromString('fm', "This archive has been generated by simogeo's Filemanager : https://github.com/simogeo/Filemanager/");
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($files as $file) {
             $file = str_replace('\\', '/', realpath($file));
             if (is_dir($file) === true) {
                 $zip->addEmptyDir(str_replace($source . '/', '', $flag . $file . '/'));
             } else {
                 if (is_file($file) === true) {
                     $zip->addFromString(str_replace($source . '/', '', $flag . $file), file_get_contents($file));
                 }
             }
         }
     } else {
         if (is_file($source) === true) {
             $zip->addFromString($flag . basename($source), file_get_contents($source));
         }
     }
     return $zip->close();
 }
Example #7
Show file File: OssnComponents.php Project: aidovoga/opensource-socialnetwork
0
 /**
  * Upload component
  *
  * @requires component package file,
  *
  * @return bool;
  */
 public function upload()
 {
     $archive = new ZipArchive();
     $data_dir = ossn_get_userdata('tmp/components');
     if (!is_dir($data_dir)) {
         mkdir($data_dir, 0755, true);
     }
     $zip = $_FILES['com_file'];
     $newfile = "{$data_dir}/{$zip['name']}";
     if (move_uploaded_file($zip['tmp_name'], $newfile)) {
         if ($archive->open($newfile) === TRUE) {
             $archive->extractTo($data_dir);
             //make community components works on installer #394
             $validate = $archive->statIndex(0);
             $validate = str_replace('/', '', $validate['name']);
             $archive->close();
             if (is_dir("{$data_dir}/{$validate}") && is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) {
                 $archive->open($newfile);
                 $archive->extractTo(ossn_route()->com);
                 $archive->close();
                 $this->newCom($validate);
                 OssnFile::DeleteDir($data_dir);
                 return true;
             }
         }
     }
     return false;
 }
Example #8
Show file File: wprp.hm.backup.php Project: phpwomen/combell
0
 /**
  * Set up the ZipArchive instance if ZipArchive is available
  */
 protected function &setup_ziparchive()
 {
     // Instance is already open
     if (!empty($this->ziparchive)) {
         $this->ziparchive->open($this->get_archive_filepath(), ZIPARCHIVE::CREATE);
         return $this->ziparchive;
     }
     $ziparchive = new ZipArchive();
     // Try opening ZipArchive
     if (!file_exists($this->get_archive_filepath())) {
         $ret = $ziparchive->open($this->get_archive_filepath(), ZIPARCHIVE::CREATE);
     } else {
         $ret = $ziparchive->open($this->get_archive_filepath());
     }
     // File couldn't be opened
     if (!$ret) {
         return false;
     }
     // Try closing ZipArchive
     $ret = $ziparchive->close();
     // File couldn't be closed
     if (!$ret) {
         return false;
     }
     // Open it once more
     if (!file_exists($this->get_archive_filepath())) {
         $ziparchive->open($this->get_archive_filepath(), ZIPARCHIVE::CREATE);
     } else {
         $ziparchive->open($this->get_archive_filepath());
     }
     $this->ziparchive = $ziparchive;
     return $this->ziparchive;
 }
Example #9
Show file File: XLSXWriter.php Project: churchcommunitybuilder/XLSXWriter
0
 public function writeToFile($filename)
 {
     @unlink($filename);
     //if the zip already exists, overwrite it
     $zip = new ZipArchive();
     if (empty($this->sheets_meta)) {
         self::log("Error in " . __CLASS__ . "::" . __FUNCTION__ . ", no worksheets defined.");
         return;
     }
     if (!$zip->open($filename, ZipArchive::CREATE)) {
         self::log("Error in " . __CLASS__ . "::" . __FUNCTION__ . ", unable to create zip.");
         return;
     }
     $zip->addEmptyDir("docProps/");
     $zip->addFromString("docProps/app.xml", self::buildAppXML());
     $zip->addFromString("docProps/core.xml", self::buildCoreXML());
     $zip->addEmptyDir("_rels/");
     $zip->addFromString("_rels/.rels", self::buildRelationshipsXML());
     $zip->addEmptyDir("xl/worksheets/");
     foreach ($this->sheets_meta as $sheet_meta) {
         $zip->addFile($sheet_meta['filename'], "xl/worksheets/" . $sheet_meta['xmlname']);
     }
     if (!empty($this->shared_strings)) {
         $zip->addFile($this->writeSharedStringsXML(), "xl/sharedStrings.xml");
         //$zip->addFromString("xl/sharedStrings.xml",     self::buildSharedStringsXML() );
     }
     $zip->addFromString("xl/workbook.xml", self::buildWorkbookXML());
     $zip->addFile($this->writeStylesXML(), "xl/styles.xml");
     //$zip->addFromString("xl/styles.xml"           , self::buildStylesXML() );
     $zip->addFromString("[Content_Types].xml", self::buildContentTypesXML());
     $zip->addEmptyDir("xl/_rels/");
     $zip->addFromString("xl/_rels/workbook.xml.rels", self::buildWorkbookRelsXML());
     $zip->close();
 }
Example #10
Show file File: Admin.php Project: hyrmedia/builderengine
0
 public function install_product($product_id)
 {
     $response = $this->communication->request('get_product_system_information', $product_id);
     if ($response->status != "success") {
         die("error");
     }
     @mkdir(APPPATH . 'download');
     $file = $this->communication->request_raw('download_product', $product_id);
     file_put_contents(APPPATH . "download/download.zip", $file);
     if (file_exists(APPPATH . "download/download.zip")) {
         PC::builder_market("Downloaded product zip.");
     } else {
         PC::builder_market("Unable to download product zip.");
     }
     $product = new Product();
     $product->remote_id = $response->info->product_id;
     $product->type = $response->info->type;
     $product->version = $response->info->version;
     $product->save();
     switch ($response->info->type) {
         case "theme":
             $zip = new ZipArchive();
             $file_path = APPPATH . "download/download.zip";
             if ($zip->open($file_path) === TRUE) {
                 $zip->extractTo(APPPATH . '../themes');
                 $zip->close();
                 unlink(APPPATH . "download/download.zip");
                 echo 'success';
             } else {
                 echo 'failed';
             }
             break;
         case "module":
             $zip = new ZipArchive();
             $file_path = APPPATH . "download/download.zip";
             if ($zip->open($file_path) === TRUE) {
                 $zip->extractTo(APPPATH . '../modules');
                 PC::builder_market("Zip extracted successfully.");
                 $folder = $zip->getNameIndex(0);
                 $folder = str_replace("/", "", $folder);
                 PC::builder_market("Unzipped folder " . $folder);
                 //$this->load->module('module_system/admin');
                 //$this->load->module('module_system');
                 //$this->module_system->admin->install();
                 echo Modules::run_with_params("module_system/install", array($folder));
                 $zip->close();
                 unlink(APPPATH . "download/download.zip");
                 echo "success";
             } else {
                 PC::builder_market("Unable to extract zip.");
                 echo 'failed';
             }
             break;
     }
 }
Example #11
Show file File: site_backup.php Project: praveenpgoswami/codeigniter_project
0
function zipFile($source, $destination, $flag = '')
{
    if (!extension_loaded('zip') || !file_exists($source)) {
        return false;
    }
    $zip = new ZipArchive();
    if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
        return false;
    }
    $source = str_replace('\\', '/', realpath($source));
    if ($flag) {
        $flag = basename($source) . '/';
        //$zip->addEmptyDir(basename($source) . '/');
    }
    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        foreach ($files as $file) {
            $file = str_replace('\\', '/', realpath($file));
            if (is_dir($file) === true) {
                $zip->addEmptyDir(str_replace($source . '/', '', $flag . $file . '/'));
            } else {
                if (is_file($file) === true) {
                    $zip->addFromString(str_replace($source . '/', '', $flag . $file), file_get_contents($file));
                }
            }
        }
    } else {
        if (is_file($source) === true) {
            $zip->addFromString($flag . basename($source), file_get_contents($source));
        }
    }
    echo "Successfully Ziped Folder";
    header('Location:admin/dashboard/admin_dashboard');
    return $zip->close();
}
Example #12
Show file File: extension_manager.php Project: betsyzhang/chyrp
0
 public function route_makeRequest()
 {
     $type = pluralize(strip_tags($_GET['type']));
     set_time_limit(0);
     $fp = fopen("../{$type}/latest.zip", 'w+');
     $url = str_replace(" ", "%20", strip_tags($_GET['url']));
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_TIMEOUT, 50);
     curl_setopt($ch, CURLOPT_FILE, $fp);
     # write curl response to file
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_exec($ch);
     curl_close($ch);
     fclose($fp);
     $zip = new ZipArchive();
     if ($zip->open("../{$type}/latest.zip") == true) {
         mkdir("../{$type}/latest", 0777);
         $zip->extractTo("../{$type}/latest");
         $zip->close();
         $handle = opendir("../{$type}/latest");
         if ($handle) {
             while (($file = readdir($handle)) !== false) {
                 if (is_dir("../{$type}/latest/{$file}")) {
                     if ($file != '.' and $file != '..') {
                         rename("../{$type}/latest/{$file}", "../{$type}/{$file}");
                     }
                 }
             }
         }
         $this->rrmdir("../{$type}/latest");
         unlink("../{$type}/latest.zip");
         $this->rrmdir("../{$type}/__MACOSX");
     }
     Flash::notice(__("Extension downloaded successfully.", "extension_manager"), "/admin/?action=extend_manager");
 }
Example #13
Show file File: Word2007.php Project: matiasvillanueva/laravel5-CRUD-LOGIN
0
 /**
  * Add footnotes/endnotes
  *
  * @param \PhpOffice\PhpWord\Shared\ZipArchive $zip
  * @param integer &$rId
  * @param string $noteType
  * @return void
  */
 private function addNotes(ZipArchive $zip, &$rId, $noteType = 'footnote')
 {
     $phpWord = $this->getPhpWord();
     $noteType = $noteType == 'endnote' ? 'endnote' : 'footnote';
     $partName = "{$noteType}s";
     $method = 'get' . $partName;
     $collection = $phpWord->{$method}();
     // Add footnotes media files, relations, and contents
     /** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collection Type hint */
     if ($collection->countItems() > 0) {
         $media = Media::getElements($noteType);
         $this->addFilesToPackage($zip, $media);
         $this->registerContentTypes($media);
         $this->contentTypes['override']["/word/{$partName}.xml"] = $partName;
         $this->relationships[] = array('target' => "{$partName}.xml", 'type' => $partName, 'rID' => ++$rId);
         // Write relationships file, e.g. word/_rels/footnotes.xml
         if (!empty($media)) {
             /** @var \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart $writerPart Type hint */
             $writerPart = $this->getWriterPart('relspart')->setMedia($media);
             $zip->addFromString("word/_rels/{$partName}.xml.rels", $writerPart->write());
         }
         // Write content file, e.g. word/footnotes.xml
         $writerPart = $this->getWriterPart($partName)->setElements($collection->getItems());
         $zip->addFromString("word/{$partName}.xml", $writerPart->write());
     }
 }
Example #14
Show file File: archive.class.php Project: bbspike/sentora-core
0
 /**
  * Uncompresses a ZIP archive to a given location.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @param string $archive Full path and filename to the ZIP archive.
  * @param string $dest The full path to the folder to extract the archive into (with trailing slash!)
  * @return boolean 
  */
 static function Unzip($archive, $dest)
 {
     global $zlo;
     if (!class_exists('ZipArchive')) {
         return false;
     }
     $zip = new ZipArchive();
     $result = $zip->open($archive);
     if ($result) {
         if (@$zip->extractTo($dest)) {
             $zip->close();
             return true;
         } else {
             $zlo->logcode = "623";
             $zlo->detail = "Unable to extract file '" . $archive . "' to '" . $dest . "'.";
             $zlo->writeLog();
             return false;
         }
     } else {
         $zlo->logcode = "621";
         $zlo->detail = "The archive file '" . $archive . "' appears to be invalid.";
         $zlo->writeLog();
         return false;
     }
 }
Example #15
Show file File: updater.php Project: omusico/isle-web-framework
0
 public static function update($version, $backupBase)
 {
     if (!is_dir($backupBase)) {
         throw new \Exception("Backup directory {$backupBase} is not found");
     }
     set_include_path($backupBase . PATH_SEPARATOR . $backupBase . '/core/lib' . PATH_SEPARATOR . $backupBase . '/core/config' . PATH_SEPARATOR . $backupBase . '/3rdparty' . PATH_SEPARATOR . $backupBase . '/apps' . PATH_SEPARATOR . get_include_path());
     $tempDir = self::getTempDir();
     Helper::mkdir($tempDir, true);
     $installed = Helper::getDirectories();
     $sources = Helper::getSources($version);
     try {
         $thirdPartyUpdater = new Location_3rdparty($installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME]);
         $thirdPartyUpdater->update($tempDir . '/' . Helper::THIRDPARTY_DIRNAME);
         self::$processed[] = $thirdPartyUpdater;
         $coreUpdater = new Location_Core($installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME]);
         $coreUpdater->update($tempDir . '/' . Helper::CORE_DIRNAME);
         self::$processed[] = $coreUpdater;
         $appsUpdater = new Location_Apps('', $sources[Helper::APP_DIRNAME]);
         $appsUpdater->update($tempDir . '/' . Helper::APP_DIRNAME);
         self::$processed[] = $appsUpdater;
     } catch (\Exception $e) {
         self::rollBack();
         self::cleanUp();
         throw $e;
     }
     // zip backup
     $zip = new \ZipArchive();
     if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true) {
         Helper::addDirectoryToZip($zip, $backupBase, $backupBase);
         $zip->close();
         \OCP\Files::rmdirr($backupBase);
     }
     return true;
 }
Example #16
Show file File: installer.php Project: monkeychen/website
0
 public function unzip()
 {
     $this->load->language('extension/installer');
     $json = array();
     if (!$this->user->hasPermission('modify', 'extension/installer')) {
         $json['error'] = $this->language->get('error_permission');
     }
     // Sanitize the filename
     $file = DIR_UPLOAD . str_replace(array('../', '..\\', '..'), '', $this->request->post['path']) . '/upload.zip';
     if (!file_exists($file)) {
         $json['error'] = $this->language->get('error_file');
     }
     if (!$json) {
         // Unzip the files
         $zip = new ZipArchive();
         if ($zip->open($file)) {
             $zip->extractTo(DIR_UPLOAD . str_replace(array('../', '..\\', '..'), '', $this->request->post['path']));
             $zip->close();
         } else {
             $json['error'] = $this->language->get('error_unzip');
         }
         // Remove Zip
         unlink($file);
     }
     $this->response->addHeader('Content-Type: application/json');
     $this->response->setOutput(json_encode($json));
 }
Example #17
Show file File: functions.inc.php Project: famry/fameCMSv2
0
 static function ZipDir($path, $zipFile, $zipPath = '')
 {
     $zip = new ZipArchive();
     $zip->open($zipFile, ZIPARCHIVE::CREATE);
     self::ZipAddDir($path, $zip, $zipPath);
     $zip->close();
 }