本文整理汇总了PHP中ZipArchive::statIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::statIndex方法的具体用法?PHP ZipArchive::statIndex怎么用?PHP ZipArchive::statIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive::statIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract
/**
* 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;
}
示例2: upload
/**
* 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;
}
示例3: action
public function action($parent)
{
$c = $parent->config;
$util = new Utility();
if (strpos($_POST['path'], '/') === 0 || strpos($_POST['path'], '../') !== false || strpos($_POST['path'], './') === 0) {
$this->r = array('wrong path', 400);
return;
}
$path = $c['current_path'] . $_POST['path'];
$info = pathinfo($path);
$base_folder = $c['current_path'] . $util->fix_dirname($_POST['path']) . "/";
switch ($info['extension']) {
case "zip":
$zip = new \ZipArchive();
if ($zip->open($path) === true) {
//make all the folders
for ($i = 0; $i < $zip->numFiles; $i++) {
$OnlyFileName = $zip->getNameIndex($i);
$FullFileName = $zip->statIndex($i);
if (substr($FullFileName['name'], -1, 1) == "/") {
$util->create_folder($base_folder . $FullFileName['name']);
}
}
//unzip into the folders
for ($i = 0; $i < $zip->numFiles; $i++) {
$OnlyFileName = $zip->getNameIndex($i);
$FullFileName = $zip->statIndex($i);
if (!(substr($FullFileName['name'], -1, 1) == "/")) {
$fileinfo = pathinfo($OnlyFileName);
if (in_array(strtolower($fileinfo['extension']), $ext)) {
copy('zip://' . $path . '#' . $OnlyFileName, $base_folder . $FullFileName['name']);
}
}
}
$zip->close();
} else {
$this->r = array('Could not extract. File might be corrupt.', 500);
return;
}
break;
case "gz":
$p = new \PharData($path);
$p->decompress();
// creates files.tar
break;
case "tar":
// unarchive from the tar
$phar = new \PharData($path);
$phar->decompressFiles();
$files = array();
$util->check_files_extensions_on_phar($phar, $files, '', $ext);
$phar->extractTo($current_path . fix_dirname($_POST['path']) . "/", $files, true);
break;
default:
$this->r = array('This extension is not supported. Valid: zip, gz, tar.', 400);
return;
break;
}
}
示例4: getPluginNamespace
/**
* @param \ZipArchive $stream
* @return string
*/
private function getPluginNamespace(\ZipArchive $stream)
{
$segments = $stream->statIndex(0);
$segments = array_filter(explode('/', $segments['name']));
if (count($segments) <= 1) {
$segments = $stream->statIndex(1);
$segments = array_filter(explode('/', $segments['name']));
}
if (!in_array($segments[0], ['Frontend', 'Backend', 'Core'])) {
throw new \RuntimeException(sprintf('Uploaded zip archive contains no plugin namespace directory: %s', $segments[1]));
}
return implode('/', $segments);
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->georgiaVoterService->setConnectionName($input->getArgument('dbname'));
if ($input->getOption('config')) {
$this->georgiaVoterService->setConfigFolder($input->getOption('config'));
}
// setConfigFolder
$zip = new \ZipArchive();
$res = $zip->open($input->getArgument('zipFile'));
if ($res === TRUE) {
$this->georgiaVoterService->initializeGeorgiaVoterTable();
$compressedfiles = [];
for ($i = 0; $i < $zip->numFiles; $i++) {
$compressedfiles[] = $zip->statIndex($i);
}
usort($compressedfiles, function ($a, $b) {
if ($a['size'] == $b['size']) {
return 0;
}
return $a['size'] < $b['size'] ? -1 : 1;
});
$maxentry = array_pop($compressedfiles);
$exportDate = \date("Y-m-d", $maxentry['mtime']);
$fp = $zip->getStream($maxentry['name']);
while (($buffer = fgets($fp, 4096)) !== false) {
$output->writeln($buffer);
}
} else {
$output->writeln("Zip File Problem");
}
}
示例6: testCompressFolder
public function testCompressFolder()
{
$files = array('releases-noNewPatch.xml', 'releases-patchsOnly.xml', 'releases.xml', 'folder/', 'folder/emptyFile', 'emptyFolder/');
$dest = dirname(__FILE__) . '/backup/test.zip';
$src = dirname(__FILE__) . '/sample';
taoUpdate_helpers_Zip::compressFolder($src, $dest);
$this->assertTrue(is_file($dest));
$zip = new ZipArchive();
$zip->open($dest);
foreach ($files as $file) {
$this->assertFalse($zip->locateName($file) === false, $file . ' not found');
}
$this->assertFalse($zip->locateName('.svn'));
helpers_File::remove($dest);
$dest = dirname(__FILE__) . '/backup/test2.zip';
taoUpdate_helpers_Zip::compressFolder($src, $dest, true);
$files = array('sample/releases-noNewPatch.xml', 'sample/releases-patchsOnly.xml', 'sample/releases.xml', 'sample/folder/', 'sample/folder/emptyFile', 'sample/emptyFolder/');
$this->assertTrue(is_file($dest));
$zip = new ZipArchive();
$zip->open($dest);
for ($i = 0; $i < $zip->numFiles; $i++) {
$stat = $zip->statIndex($i);
//cehck no .svn added in zip
$this->assertFalse(strpos($stat['name'], '.svn') > 0);
}
foreach ($files as $file) {
$this->assertFalse($zip->locateName($file) === false);
}
helpers_File::remove($dest);
}
示例7: import
function import($inputFile, $targetDirectory = null)
{
if (!$targetDirectory) {
$targetDirectory = '';
}
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $inputFile);
finfo_close($finfo);
switch ($type) {
case 'application/zip':
$zip = new ZipArchive();
$zip->open($inputFile);
$i = 0;
while ($i < $zip->numFiles) {
$file = $zip->statIndex($i);
$contents = '';
$fp = $zip->getStream($file['name']);
while (!feof($fp)) {
$contents .= fread($fp, 2);
}
SiteCollection::createFile($targetDirectory . $file['name'], $contents);
fclose($fp);
$i++;
}
break;
default:
throw new Exception('MIME type ' . $type . ' unsupported.');
}
}
示例8: execute
public function execute($args)
{
if ($args) {
$file = $args[0];
if (file_exists($file) && \Clips\is_zip($file)) {
switch (count($args)) {
case 1:
$p = new \ZipArchive();
$p->open($file);
for ($i = 0; $i < $p->numFiles; $i++) {
$stat = $p->statIndex($i);
echo $stat['name'] . PHP_EOL;
print_r($stat);
}
break;
default:
echo \Clips\zip_contents($file, $args[1]);
}
} else {
$this->error("The file {$file} is not exists or is not a phar file!");
}
} else {
$this->error('No phar file input!');
}
}
示例9: importtables
public function importtables($thisfolder) { // the main sub in our application
$PHP_EOL = "\r\n";
// if (file_exists($filename)) unlink ($filename);
$za = new ZipArchive();
$za->open($thisfolder.'/update.zip');
// if ($txt=="update") {
echo "Files in zip archive: ".$za->numFiles.$PHP_EOL;
echo "Extracting to ".$thisfolder."".$PHP_EOL;
$za->extractTo($thisfolder."");
// } else {
// echo "Single table mode".$PHP_EOL;
// }
$tablenames = array(
'Money'
);
// 'Projects'
$filenames = array(
'Money.dbu'
);
// 'Projects.dbu'
echo "------\r";
for($i = 0; $i < $za->numFiles; $i++) {
$stat = $za->statIndex($i);
if (in_array($stat['name'],$filenames)) {
$filename=$thisfolder."/".$stat['name'];
if (file_exists($filename)) echo $filename." extracted successfully".$PHP_EOL;
}
}
echo "------\r";
for($i = 0; $i < sizeof($filenames); $i++) {
$filename=$thisfolder."/".$filenames[$i];
if (file_exists($filename)) {
echo "Reading data from ".$filenames[$i].$PHP_EOL;
$file = conv(file_get_contents($filename));
$json = json_decode($file);
if (sizeof($json)) {
echo "Importing data (".strlen($file)." Kb)".$PHP_EOL;
$this->importtable($json, $txt);
} else {
echo "JSON decode error ".echo_jerror(json_last_error()).$PHP_EOL;
}
echo "------\r";
} else {
echo "File not found".$PHP_EOL;
}
}
// ajax_echo_r(json_last_error());
// echo_r($json);
if ($za->numFiles) {
$za->close();
}
}
示例10: locateFile
private function locateFile(\ZipArchive $zip, $filename)
{
$indexOfShortestMatch = false;
$lengthOfShortestMatch = -1;
for ($i = 0; $i < $zip->numFiles; $i++) {
$stat = $zip->statIndex($i);
if (strcmp(basename($stat['name']), $filename) === 0) {
$directoryName = dirname($stat['name']);
if ($directoryName == '.') {
return $i;
}
if (strpos($directoryName, '\\') !== false || strpos($directoryName, '/') !== false) {
continue;
}
$length = strlen($stat['name']);
if ($indexOfShortestMatch == false || $length < $lengthOfShortestMatch) {
$contents = $zip->getFromIndex($i);
if ($contents !== false) {
$indexOfShortestMatch = $i;
$lengthOfShortestMatch = $length;
}
}
}
}
return $indexOfShortestMatch;
}
示例11: testExportData
/**
* test export data
*/
public function testExportData() {
$dao = new BackupMySQLDAO();
$export_file = $dao->export();
$this->assertTrue( file_exists($export_file) );
$zip_stats = stat($export_file);
$this->assertTrue($zip_stats['size'] > 0);
$za = new ZipArchive();
$za->open($export_file);
$zip_files = array();
for ($i=0; $i<$za->numFiles;$i++) {
$zfile = $za->statIndex($i);
$zip_files[$zfile['name']] = $zfile['name'];
}
//verify we have create table file
$this->assertTrue($zip_files["create_tables.sql"]);
$za->close();
$q = "show tables";
$q2 = "show create table ";
$stmt = $this->pdo->query($q);
// verify we have all table files
while($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
foreach($data as $key => $value) {
$zfile = '/' . $value .'.txt';
$this->assertTrue($zip_files[$zfile]);
}
}
}
示例12: url_stat
public function url_stat($path, $flags)
{
$ret = [];
$zippath = preg_replace('/^myzip:\\/\\//', "", $path);
$parts = explode('#', $zippath, 2);
if (count($parts) != 2) {
return false;
}
list($zippath, $subfile) = $parts;
$za = new \ZipArchive();
if ($za->open($zippath) !== true) {
return false;
}
$i = $za->locateName($subfile);
if ($i === false) {
return false;
}
$zst = $za->statIndex($i);
$za->close();
unset($za);
foreach ([7 => 'size', 8 => 'mtime', 9 => 'mtime', 10 => 'mtime'] as $a => $b) {
if (!isset($zst[$b])) {
continue;
}
$ret[$a] = $zst[$b];
}
return $ret;
}
示例13: processPluginsFolder
function processPluginsFolder($folder, $requiredMpsVersion, $pluginsVersion)
{
$files = scandir($folder);
foreach ($files as $zipfile) {
if (pathinfo($zipfile, PATHINFO_EXTENSION) == 'zip') {
$za = new ZipArchive();
$za->open($folder . $zipfile);
for ($i = 0; $i < $za->numFiles; $i++) {
$stat = $za->statIndex($i);
$pluginXmlFile = $stat['name'];
if (endsWith($pluginXmlFile, "META-INF/plugin.xml")) {
$stream = $za->getStream($pluginXmlFile);
$content = stream_get_contents($stream);
$xml = simplexml_load_string($content);
if (fixPluginXml($xml, $requiredMpsVersion, $pluginsVersion)) {
$za->deleteName($pluginXmlFile);
$za->addFromString($pluginXmlFile, $xml->asXML());
}
printPluginXml($xml, $zipfile, $requiredMpsVersion, $pluginsVersion);
break;
}
}
}
}
}
示例14: getZippedFile
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;
}
示例15: import
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);
}
}