function unzip_content() { $zip = new ZipArchive(); if (file_exists('application.zip')) { $res = $zip->open('application.zip'); if ($res === TRUE) { echo '<p>Unzipped Application <i class="fa fa-check-circle-o"></i></p>'; $zip->extractTo('./'); $zip->close(); unlink('application.zip'); } else { echo '<p>Could not unzip application.zip <i class="fa fa-times-circle-o"></i></p>'; } } else { echo '<p>Application already unzipped <i class="fa fa-check-circle-o"></i></p>'; } new_line(); if (file_exists('content.zip')) { $res = $zip->open('content.zip'); if ($res === TRUE) { echo '<p>Unzipped Content <i class="fa fa-check-circle-o"></i></p>'; $zip->extractTo('./'); $zip->close(); unlink('content.zip'); } else { echo '<p>Could not unzip content.zip <i class="fa fa-times-circle-o"></i></p>'; } } else { echo '<p>Content already unzipped <i class="fa fa-check-circle-o"></i></p>'; } new_line(); }
function unzip_file($zip_archive, $archive_file, $zip_dir) { if (!is_dir($zip_dir)) { if (!defined('SUGAR_PHPUNIT_RUNNER')) { die("Specified directory '{$zip_dir}' for zip file '{$zip_archive}' extraction does not exist."); } return false; } $zip = new ZipArchive(); $res = $zip->open($zip_archive); if ($res !== true) { if (!defined('SUGAR_PHPUNIT_RUNNER')) { die(sprintf("ZIP Error(%d): %s", $res, $zip->status)); } return false; } if ($archive_file !== null) { $res = $zip->extractTo($zip_dir, $archive_file); } else { $res = $zip->extractTo($zip_dir); } if ($res !== true) { if (!defined('SUGAR_PHPUNIT_RUNNER')) { die(sprintf("ZIP Error(%d): %s", $res, $zip->status)); } return false; } return true; }
/** * @param $destination * @throws IfwPsn_Wp_Module_Exception * @return bool */ public function extractTo($destination) { if (!$this->_zip->extractTo($destination)) { throw new IfwPsn_Wp_Module_Exception('Could not extract archive.'); } return true; }
/** * Test all methods * * @param string $zipClass * @covers ::<public> */ public function testZipArchive($zipClass = 'ZipArchive') { // Preparation $existingFile = __DIR__ . '/../_files/documents/sheet.xls'; $zipFile = __DIR__ . '/../_files/documents/ziptest.zip'; $destination1 = __DIR__ . '/../_files/documents/extract1'; $destination2 = __DIR__ . '/../_files/documents/extract2'; @mkdir($destination1); @mkdir($destination2); Settings::setZipClass($zipClass); $object = new ZipArchive(); $object->open($zipFile, ZipArchive::CREATE); $object->addFile($existingFile, 'xls/new.xls'); $object->addFromString('content/string.txt', 'Test'); $object->close(); $object->open($zipFile); // Run tests $this->assertEquals(0, $object->locateName('xls/new.xls')); $this->assertFalse($object->locateName('blablabla')); $this->assertEquals('Test', $object->getFromName('content/string.txt')); $this->assertEquals('Test', $object->getFromName('/content/string.txt')); $this->assertFalse($object->getNameIndex(-1)); $this->assertEquals('content/string.txt', $object->getNameIndex(1)); $this->assertFalse($object->extractTo('blablabla')); $this->assertTrue($object->extractTo($destination1)); $this->assertTrue($object->extractTo($destination2, 'xls/new.xls')); $this->assertFalse($object->extractTo($destination2, 'blablabla')); // Cleanup $this->deleteDir($destination1); $this->deleteDir($destination2); @unlink($zipFile); }
/** * 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; }
/** * @param string $to - path where the archive should be extracted to * @return bool */ public function extract($to) { $r = false; $ext = SPFs::getExt($this->_filename); switch ($ext) { case 'zip': $zip = new ZipArchive(); if ($zip->open($this->_filename) === true) { SPException::catchErrors(SPC::WARNING); try { $zip->extractTo($to); $zip->close(); $r = true; } catch (SPException $x) { $t = Sobi::FixPath(Sobi::Cfg('fs.temp') . DS . md5(microtime())); SPFs::mkdir($t, 0777); $dir = SPFactory::Instance('base.fs.directory', $t); if ($zip->extractTo($t)) { $zip->close(); $dir->moveFiles($to); $r = true; } SPFs::delete($dir->getPathname()); } SPException::catchErrors(0); } break; } return $r; }
private function extractArchive() { $this->archive->close(); $this->archive->open($this->archive_path); $this->archive->extractTo($this->extraction_path); $this->archive->close(); }
/** * Extract files from archive to target directory * * @param string $pathExtracted Absolute path of target directory * @return mixed Array of filenames if successful; or 0 if an error occurred */ public function extract($pathExtracted) { if (substr_compare($pathExtracted, '/', -1)) { $pathExtracted .= '/'; } $fileselector = array(); $list = array(); $count = $this->ziparchive->numFiles; if ($count === 0) { return 0; } for ($i = 0; $i < $count; $i++) { $entry = $this->ziparchive->statIndex($i); $filename = str_replace('\\', '/', $entry['name']); $parts = explode('/', $filename); if (!strncmp($filename, '/', 1) || array_search('..', $parts) !== false || strpos($filename, ':') !== false) { return 0; } $fileselector[] = $entry['name']; $list[] = array('filename' => $pathExtracted . $entry['name'], 'stored_filename' => $entry['name'], 'size' => $entry['size'], 'compressed_size' => $entry['comp_size'], 'mtime' => $entry['mtime'], 'index' => $i, 'crc' => $entry['crc']); } $res = $this->ziparchive->extractTo($pathExtracted, $fileselector); if ($res === false) { return 0; } return $list; }
/** * 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); $archive->close(); $validate = pathinfo($zip['name'], PATHINFO_FILENAME); if (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; }
function unzip_file($zip_archive, $archive_file, $zip_dir) { if (!is_dir($zip_dir)) { if (defined('SUGAR_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) { $GLOBALS['log']->fatal("Specified directory '{$zip_dir}' for zip file '{$zip_archive}' extraction does not exist."); return false; } else { die("Specified directory '{$zip_dir}' for zip file '{$zip_archive}' extraction does not exist."); } } $zip = new ZipArchive(); $res = $zip->open($zip_archive); if ($res !== TRUE) { if (defined('SUGAR_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) { $GLOBALS['log']->fatal(sprintf("ZIP Error(%d): Status(%s): Arhive(%s): Directory(%s)", $res, $zip->status, $zip_archive, $zip_dir)); return false; } else { die(sprintf("ZIP Error(%d): Status(%s): Arhive(%s): Directory(%s)", $res, $zip->status, $zip_archive, $zip_dir)); } } if ($archive_file !== null) { $res = $zip->extractTo($zip_dir, $archive_file); } else { $res = $zip->extractTo($zip_dir); } if ($res !== TRUE) { if (defined('SUGAR_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) { $GLOBALS['log']->fatal(sprintf("ZIP Error(%d): Status(%s): Arhive(%s): Directory(%s)", $res, $zip->status, $zip_archive, $zip_dir)); return false; } else { die(sprintf("ZIP Error(%d): Status(%s): Arhive(%s): Directory(%s)", $res, $zip->status, $zip_archive, $zip_dir)); } } return true; }
/** * Extract an archived and/or compressed file * * @param string $to * @return void */ public function extract($to = null) { if ($this->archive->open($this->path) === true) { $path = null !== $to ? realpath($to) : './'; $this->archive->extractTo($path); $this->archive->close(); } }
/** * {@inheritdoc} */ public function extract($path, array $files = array()) { if ($files) { $this->zip->extractTo($path, $files); } else { $this->zip->extractTo($path); } return $this; }
/** * ZipArchive クラスによる展開 * * @param $source * @param $target * @return bool */ protected function _extractByPhpLib($source, $target) { if ($this->Zip->open($source) === true && $this->Zip->extractTo($target)) { $archivePath = $this->Zip->getNameIndex(0); $archivePathAry = explode(DS, $archivePath); $this->topArchiveName = $archivePathAry[0]; return true; } else { return false; } }
/** * Metodo utilizzato per estrarre i tracciati dati e immagini * nella cartella import */ function extractFileIntoFolder() { $zip = new \ZipArchive(); $res = $zip->open(FOLDER_IMPORT_ROOT . FILE_ERP_DATA); if ($res === TRUE) { $zip->extractTo(FOLDER_UNZIP); $zip->close(); } $res2 = $zip->open(FOLDER_IMPORT_ROOT . FILE_ERP_IMG); if ($res2 === TRUE) { $zip->extractTo(FOLDER_UNZIP); $zip->close(); } }
/** * 'upload_zip' upload field must refer to a zip file containing * all files for the pubnode (may be at top-level or inside a subdirectory) */ public function import(&$form_state, $docid = NULL) { $validators = array('file_validate_extensions' => array('zip'), 'file_validate_size' => array(100000000, 0)); if ($file = file_save_upload($this->fieldname, $validators, file_directory_temp(), FILE_EXISTS_REPLACE)) { $zip = new ZipArchive(); if ($zip->open($file->filepath) !== TRUE) { form_set_error(t("Cannot open !file", array("!file" => $file->filename)), 'error'); return FALSE; } // else if (empty($docid)) { $docid = $this->hashFile($file->filepath); } $pubpath = $this->constructPubPath($docid); //drupal_set_message("PUBPATH: " . $pubpath); file_check_directory($pubpath, FILE_CREATE_DIRECTORY); $zip->extractTo($pubpath); drupal_set_message(t("Extracted !num files to directory !dir", array('!num' => $zip->numFiles, '!dir' => $pubpath))); $zip->close(); $this->pubpath = $pubpath; return TRUE; } // else validations failed and error message will be set by upload function return FALSE; }
/** * @param string * @param string */ private function unpackZip($zipPath, $dataPath) { if ($this->verbose) { $this->writeln('Unpacking pages zip file'); } if (file_exists($dataPath)) { try { FileSystem::delete($dataPath); } catch (\Nette\IOException $e) { throw new \NetteAddons\InvalidStateException('Pages temp data directory already exists'); } } $zip = new \ZipArchive(); if ($err = $zip->open($zipPath) !== TRUE) { throw new \NetteAddons\InvalidStateException('Pages zip file is corrupted', $err); } if (!mkdir($dataPath, 0777, TRUE)) { throw new \NetteAddons\InvalidStateException('Pages temp data directory could not be created'); } if (!$zip->extractTo($dataPath)) { throw new \NetteAddons\InvalidStateException('Pages zip file is corrupted'); } $zip->close(); unlink($zipPath); }
private static function getZippedFile($filename) { if(!self::zipModuleLoaded()) { throw new WURFL_WURFLException("The Zip extension is not loaded. Load the extension or use the flat wurfl.xml file"); } $tmpDir = sys_get_temp_dir(); $zip = new ZipArchive(); if ($zip->open($filename)!==TRUE) { exit("cannot open <$filename>\n"); } $zippedFile = $zip->statIndex(0); $wurflFile = $zippedFile['name']; //$wurflFile = md5(uniqid(rand(), true)); //$zip->extractTo($tmpDir, $wurflFile); $zip->extractTo($tmpDir); $zip->close(); return $tmpDir . '/' .$wurflFile; }
/** * Prepare clean SMF forum */ public function forumPrepare() { $version = $this->askDefault("SMF Core Version", self::SMF_VERSION); // download $zipFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'smf-' . $version . '.zip'; if (!file_exists($zipFile)) { $url = 'http://download.simplemachines.org/index.php/smf_' . str_replace('.', '-', $version) . '_install.zip'; file_put_contents($zipFile, fopen($url, 'r')); } // clean dir $dir = $this->askDefault("Install directory path", '/var/www/html/smf'); if (is_dir($dir)) { $clean = $this->askDefault('Directory exists. Clean ' . $dir, 'y'); if ($clean == 'y') { $this->taskCleanDir([$dir])->run(); } } // extract $zip = new ZipArchive(); if ($zip->open($zipFile) === true) { $zip->extractTo($dir); $zip->close(); $this->say('Extracted ' . $zipFile); } // fix file and folder access $this->taskExecStack()->stopOnFail()->exec('chown www-data:www-data -R ' . $dir)->exec('chmod og+rwx -R ' . $dir)->run(); //database $dbName = $this->askDefault("MySQL DB_NAME", 'smf'); $rootPassword = $this->askDefault("MySQL root password", ''); $dbh = new PDO('mysql:host=localhost', 'root', $rootPassword); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->query("DROP DATABASE IF EXISTS {$dbName}"); $dbh->query("CREATE DATABASE {$dbName}"); $this->say('Created schema ' . $dbName); }
/** * Load the XML file from the current process file as a TBS template * * @param string $xmlFilename The XML file (content.xml by default) */ public function loadXml($xmlFilename = 'content.xml') { $this->setXmlFilename($xmlFilename); // unzip the XML file into the current basename process dir switch ($this->getZipMethod()) { case 'ziparchive': $zip = new ZipArchive(); if ($zip->open($this->getPathname()) === true) { $zip->extractTo($this->getProcessDir() . DIRECTORY_SEPARATOR . $this->getBasename() . DIRECTORY_SEPARATOR, array($this->getXmlFilename())); $zip->close(); } break; case 'shell': default: $cmd = escapeshellcmd($this->getUnzipBinary()); $cmd .= ' ' . escapeshellarg($this->getPathname()); $cmd .= ' -d'; $cmd .= ' ' . escapeshellarg($this->getProcessDir() . DIRECTORY_SEPARATOR . $this->getBasename()); $cmd .= ' ' . escapeshellarg($this->getXmlFilename()); exec($cmd); break; } // test if the XML file exist if (!file_exists($this->getProcessDir() . DIRECTORY_SEPARATOR . $this->getBasename() . DIRECTORY_SEPARATOR . $this->getXmlFilename())) { throw new Exception(sprintf('Xml file not found "%s"', $this->getProcessDir() . DIRECTORY_SEPARATOR . $this->getBasename() . DIRECTORY_SEPARATOR . $this->getXmlFilename())); } // load the XML file as a TBS template $this->ObjectRef = $this; $this->LoadTemplate($this->getProcessDir() . DIRECTORY_SEPARATOR . $this->getBasename() . DIRECTORY_SEPARATOR . $this->getXmlFilename(), $this->getCallback()); // work around - convert apostrophe in XML file needed for TBS functions $this->Source = str_replace(''', '\'', $this->Source); }
/** * 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; } }
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"); }
/** * Install a bundle from by downloading a Zip. * * @param string $url * @param array $bundle * @param string $path * @return void */ protected function zipball($url, $bundle, $path) { $work = path('storage') . 'work/'; // When installing a bundle from a Zip archive, we'll first clone // down the bundle zip into the bundles "working" directory so // we have a spot to do all of our bundle extration work. $target = $work . 'laravel-bundle.zip'; File::put($target, $this->download($url)); $zip = new \ZipArchive(); $zip->open($target); // Once we have the Zip archive, we can open it and extract it // into the working directory. By convention, we expect the // archive to contain one root directory with the bundle. mkdir($work . 'zip'); $zip->extractTo($work . 'zip'); $latest = File::latest($work . 'zip')->getRealPath(); @chmod($latest, 0777); // Once we have the latest modified directory, we should be // able to move its contents over into the bundles folder // so the bundle will be usable by the develoepr. File::mvdir($latest, $path); File::rmdir($work . 'zip'); $zip->close(); @unlink($target); }
public static function importDelivery(core_kernel_classes_Class $deliveryClass, $archiveFile) { $folder = tao_helpers_File::createTempDir(); $zip = new ZipArchive(); if ($zip->open($archiveFile) === true) { if ($zip->extractTo($folder)) { $returnValue = $folder; } $zip->close(); } $manifestPath = $folder . self::MANIFEST_FILE; if (!file_exists($manifestPath)) { return common_report_Report::createFailure(__('Manifest not found in assembly')); } $manifest = json_decode(file_get_contents($manifestPath), true); $label = $manifest['label']; $serviceCall = tao_models_classes_service_ServiceCall::fromString(base64_decode($manifest['runtime'])); $dirs = $manifest['dir']; $resultServer = taoResultServer_models_classes_ResultServerAuthoringService::singleton()->getDefaultResultServer(); try { foreach ($dirs as $id => $relPath) { tao_models_classes_service_FileStorage::singleton()->import($id, $folder . $relPath); } $delivery = $deliveryClass->createInstanceWithProperties(array(RDFS_LABEL => $label, PROPERTY_COMPILEDDELIVERY_DIRECTORY => array_keys($dirs), PROPERTY_COMPILEDDELIVERY_TIME => time(), PROPERTY_COMPILEDDELIVERY_RUNTIME => $serviceCall->toOntology(), TAO_DELIVERY_RESULTSERVER_PROP => $resultServer)); $report = common_report_Report::createSuccess(__('Delivery "%s" successfully imported', $label), $delivery); } catch (Exception $e) { if (isset($delivery) && $delivery instanceof core_kernel_classes_Resource) { $delivery->delete(); } $report = common_report_Report::createFailure(__('Unkown error during impoort')); } return $report; }
/** * Unzip file */ public function unZip($fromFile, $toDir) { $zip = new ZipArchive(); $zip->open($fromFile); $zip->extractTo($toDir); $zip->close(); }
public function import($zip = null, $extra = null) { $file = PHPFOX_DIR_FILE . 'static/' . uniqid() . '/'; mkdir($file); if ($zip === null) { $zip = $file . 'import.zip'; file_put_contents($zip, file_get_contents('php://input')); } $Zip = new \ZipArchive(); $Zip->open($zip); $Zip->extractTo($file); $Zip->close(); $themeId = null; $File = \Phpfox_File::instance(); foreach (scandir($file) as $f) { if ($File->extension($f) == 'json') { $data = json_decode(file_get_contents($file . $f)); $themeId = $this->make(['name' => $data->name, 'extra' => $extra ? json_encode($extra) : null], $data->files); $File->delete_directory($file); $iteration = 0; foreach ($data->flavors as $flavorId => $flavorName) { $iteration++; $this->db->insert(':theme_style', ['theme_id' => $themeId, 'name' => $flavorName, 'folder' => $flavorId, 'is_default' => $iteration === 1 ? '1' : '0']); } } } if ($themeId === null) { throw new \Exception('Theme is missing its JSON file.'); } return $themeId; }
/** * Unzip a file into the specified directory. Throws a RuntimeException * if the extraction failed. */ public static function unzip($source, $base = null) { $base = $base ? $base : self::$folder; @ini_set('memory_limit', '256M'); if (!is_dir($base)) { mkdir($base); chmod($base, 0777); } if (class_exists('ZipArchive')) { // use ZipArchive $zip = new ZipArchive(); $res = $zip->open($source); if ($res === true) { $zip->extractTo($base); $zip->close(); } else { throw new RuntimeException('Could not open zip file [ZipArchive].'); } } else { // use PclZip $zip = new PclZip($source); if ($zip->extract(PCLZIP_OPT_PATH, $base) === 0) { throw new RuntimeException('Could not extract zip file [PclZip].'); } } return true; }
/** * Merge bin AnimeDB_Run.vbs commands. * * @param Downloaded $event */ public function onAppDownloadedMergeBinRun(Downloaded $event) { // remove startup files $this->fs->remove([$this->root_dir . 'bin/AnimeDB_Run.vbs', $this->root_dir . 'bin/AnimeDB_Stop.vbs', $this->root_dir . 'AnimeDB_Run.vbs', $this->root_dir . 'AnimeDB_Stop.vbs']); if (defined('PHP_WINDOWS_VERSION_BUILD')) { // application has not yet has the monitor if (!$this->fs->exists($this->root_dir . '/config.ini')) { $monitor = sys_get_temp_dir() . '/' . basename($this->monitor); // download monitor if need if (!$this->fs->exists($monitor)) { $this->fs->copy($this->monitor, $monitor); } // unzip if ($this->zip->open($monitor) !== true) { throw new \RuntimeException('Failed unzip monitor'); } $this->zip->extractTo($event->getPath()); $this->zip->close(); } // copy params if need $old_file = $this->root_dir . '/config.ini'; $new_file = $event->getPath() . '/config.ini'; if ($this->fs->exists($new_file) && $this->fs->exists($old_file) && is_readable($new_file) && md5_file($old_file) != md5_file($new_file)) { $old_body = file_get_contents($old_file); $new_body = $tmp_body = file_get_contents($new_file); $new_body = $this->copyParam($old_body, $new_body, 'addr=%s' . PHP_EOL, self::DEFAULT_ADDRESS); $new_body = $this->copyParam($old_body, $new_body, 'port=%s' . PHP_EOL, self::DEFAULT_PORT); $new_body = $this->copyParam($old_body, $new_body, 'php=%s' . PHP_EOL, self::DEFAULT_PHP); if ($new_body != $tmp_body) { file_put_contents($new_file, $new_body); } } } }
function createProject($name, $videoUrl, $sha1password) { $retours = array("success" => 0, "error" => "", "value" => ""); $name = sanitize($name); if ($name == "") { $name = sha1(rand()); } if (!file_exists($name)) { $zip = new ZipArchive(); $res = $zip->open("create.zip"); if ($res === TRUE) { $zip->extractTo($name); $zip->close(); file_put_contents($name . "/file/project.xml", str_replace("__video__", $videoUrl, file_get_contents($name . "/file/project.xml"))); file_put_contents($name . "/file/projectPassword.txt", $sha1password); $retours["success"] = 1; } else { $retours["success"] = -1; $retours["error"] = "No seed found"; } } else { $retours["success"] = 0; $retours["error"] = "Project already exists"; } $retours["value"] = $name; echo json_encode($retours); }
function unzipZendeskCSV($reportName) { $unzipReport = new ZipArchive(); $unzipReport->open($reportName); $unzipReport->extractTo('/var/www/reports/'); $unzipReport->close(); }
public function import($zipfile) { if (file_exists($zipfile)) { $zip = new ZipArchive(); if ($zip->open($zipfile) !== TRUE) { throw new Exception("Unable to open import file, corrupted zip file?: " . $zipfile); } else { // validate zip file $num_files = $zip->numFiles; if ($num_files < 1) { throw new Exception("Unable to open import file, corrupted zip file?: " . $zipfile); } $num_files--; $last_file = $zip->statIndex($num_files); if ($last_file['name'] != 'create_tables.sql') { throw new Exception("Unable to open import file, corrupted zip file?: " . $zipfile); } // extract zipfile // create backip dir $bkdir = THINKUP_WEBAPP_PATH . self::CACHE_DIR . '/backup'; if (!file_exists($bkdir)) { mkdir($bkdir); } $zip->extractTo($bkdir); $create_table = $bkdir . '/create_tables.sql'; $infiles = glob($bkdir . '/*.txt'); // rebuild db $sql = file_get_contents($create_table); if (getenv('BACKUP_VERBOSE') !== false) { print " Creating tables...\n\n"; } $stmt = $this->execute($sql); $stmt->closeCursor(); unlink($create_table); // import data //var_dump($infiles); foreach ($infiles as $infile) { $table = $infile; $matches = array(); if (preg_match('#.*/(\\w+).txt$#', $table, $matches)) { $table = $matches[1]; if (getenv('BACKUP_VERBOSE') !== false) { print " Restoring data for table: {$table}\n"; } $q = "LOAD DATA INFILE '{$infile}' INTO TABLE {$table}"; $stmt = $this->execute($q); if (!$stmt) { throw new Exception("unbale to load data file: " . $infile); } $stmt->closeCursor(); unlink($infile); } } rmdir($bkdir); return true; } } else { throw new Exception("Unable to open import file: " . $zipfile); } }