当前位置: 首页>>代码示例>>PHP>>正文


PHP ZipArchive::getCommentIndex方法代码示例

本文整理汇总了PHP中ZipArchive::getCommentIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::getCommentIndex方法的具体用法?PHP ZipArchive::getCommentIndex怎么用?PHP ZipArchive::getCommentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZipArchive的用法示例。


在下文中一共展示了ZipArchive::getCommentIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadIndexesFromDir

function loadIndexesFromDir($output, $outputIndexes, $dir, $elementName, $mapNodes)
{
    $local_file = basename($_SERVER['PHP_SELF']) == basename(__FILE__);
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            $zip = new ZipArchive();
            while (($file = readdir($dh)) !== false) {
                $filename = $dir . $file;
                //"./test112.zip";
                //print("processing file:" . $filename . "\n");
                if ($zip->open($filename, ZIPARCHIVE::CHECKCONS) !== TRUE) {
                    // echo exit("cannot open <$filename>\n");
                    // print($filename . " cannot open as zip\n");
                    continue;
                }
                $indexName = $file;
                $description = $zip->getCommentIndex(0);
                $stat = $zip->statIndex(0);
                $date = date('d.m.Y', $stat['mtime']);
                $size = number_format(filesize($filename) / (1024.0 * 1024.0), 1, '.', '');
                $zip->close();
                if ($local_file) {
                    echo 'Local : ' . $indexName . ' ' . $date . ' ' . $size . '<br>';
                }
                if (isset($mapNodes[$indexName])) {
                    $exdate = DateTime::createFromFormat('d.m.Y', $mapNodes[$indexName]->getAttribute("date"));
                    $localdate = DateTime::createFromFormat('d.m.Y', $date);
                    if ($localdate->getTimestamp() <= $exdate->getTimestamp()) {
                        continue;
                    }
                    $out = $mapNodes[$indexName];
                    //if($out -> getAttribute("parts")) {
                    $outputIndexes->removeChild($out);
                    $out = $output->createElement($elementName);
                    $outputIndexes->appendChild($out);
                    //}
                } else {
                    $out = $output->createElement($elementName);
                    $outputIndexes->appendChild($out);
                }
                $out->setAttribute("date", $date);
                $out->setAttribute("local", "true");
                $out->setAttribute("size", $size);
                $out->setAttribute("name", $indexName);
                $out->setAttribute("description", $description);
                //$mapNodes[$indexName] = $out;
            }
            closedir($dh);
        }
    } else {
        print $dir . " not a directory!\n";
    }
}
开发者ID:njethanandani,项目名称:Osmand,代码行数:53,代码来源:update_indexes.php

示例2: updateGoogleCodeIndexes

function updateGoogleCodeIndexes($update = false)
{
    $localFileName = 'indexes.xml';
    // check each 30 minutes
    if (!$update && file_exists($localFileName) && time() - filemtime($localFileName) < 60 * 30) {
        return;
    }
    $dom = new DomDocument();
    $output = new DOMDocument();
    $output->formatOutput = true;
    $outputIndexes = $output->createElement("osmand_regions");
    $outputIndexes->setAttribute('mapversion', '1');
    $output->appendChild($outputIndexes);
    $st = 0;
    $num = 200;
    $count = 0;
    $mapNodes = array();
    /// 1. dlownload indexes  from googlecode
    while ($st != -1) {
        $dom->loadHTMLFile("http://code.google.com/p/osmand/downloads/list?num=" . $num . "&start=" . $st . "&colspec=Filename+Summary+Uploaded+Size");
        $count++;
        $xpath = new DOMXpath($dom);
        $xpathI = new DOMXpath($dom);
        $res = $xpath->query('//td[contains(@class,"col_0")]');
        if ($res && $res->length > 0) {
            foreach ($res as $node) {
                $indexName = trim($node->nodeValue);
                $s = $xpathI->query('td[contains(@class,"col_1")]/a[1]', $node->parentNode);
                if (!$s || $s->length == 0) {
                    continue;
                }
                $description = $s->item(0)->nodeValue;
                $i = strpos($description, "{");
                if (!$i) {
                    continue;
                }
                $i1 = strpos($description, ":", $i);
                $i2 = stripos($description, "mb", $i1);
                if (!$i2) {
                    $i2 = strpos($description, "}", $i1);
                }
                $date = trim(substr($description, $i + 1, $i1 - $i - 1));
                $size = trim(substr($description, $i1 + 1, $i2 - $i1 - 1));
                $description = trim(substr($description, 0, $i));
                if (strpos($indexName, "voice.zip") || strpos($indexName, "_1.poi.zip") || strpos($indexName, "_1.poi.odb") || strpos($indexName, "_1.obf")) {
                    $ipart = strpos($indexName, "zip-");
                    $part = 1;
                    $base = $indexName;
                    if ($ipart) {
                        $part = (int) substr($indexName, $ipart + 4);
                        $base = substr($indexName, 0, $ipart + 3);
                        if (isset($mapNodes[$base])) {
                            $out = $mapNodes[$base];
                        } else {
                            $out = $output->createElement("multiregion");
                            $out->setAttribute("parts", $part);
                            $mapNodes[$base] = $out;
                            $out->setAttribute("date", $date);
                            $out->setAttribute("size", $size);
                            $out->setAttribute("name", $base);
                            $out->setAttribute("description", $description);
                            $outputIndexes->appendChild($out);
                        }
                        if ((int) $out->getAttribute("parts") < $part) {
                            $out->setAttribute("parts", $part);
                        }
                    } else {
                        $out = $output->createElement("region");
                        $out->setAttribute("date", $date);
                        $out->setAttribute("size", $size);
                        $out->setAttribute("name", $indexName);
                        $out->setAttribute("description", $description);
                        $outputIndexes->appendChild($out);
                        $mapNodes[$indexName] = $out;
                    }
                }
            }
            $st += $num;
        } else {
            $st = -1;
        }
    }
    /// 2. append local indexes
    $local = new DomDocument();
    // Open a known directory, and proceed to read its contents
    $dir = 'indexes/';
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            $zip = new ZipArchive();
            while (($file = readdir($dh)) !== false) {
                $filename = $dir . $file;
                //"./test112.zip";
                //print("processing file:" . $filename . "\n");
                if ($zip->open($filename, ZIPARCHIVE::CHECKCONS) !== TRUE) {
                    // echo exit("cannot open <$filename>\n");
                    // print($filename . " cannot open as zip\n");
                    continue;
                }
                $indexName = $file;
                $description = $zip->getCommentIndex(0);
//.........这里部分代码省略.........
开发者ID:rogere66,项目名称:Osmand,代码行数:101,代码来源:update_indexes.php

示例3: dirname

<?php

$dirname = dirname(__FILE__) . '/';
$file = $dirname . 'test_with_comment.zip';
include $dirname . 'utils.inc';
$zip = new ZipArchive();
if (!$zip->open($file)) {
    exit('failed');
}
echo $zip->getArchiveComment() . "\n";
$idx = $zip->locateName('foo');
echo $zip->getCommentName('foo') . "\n";
echo $zip->getCommentIndex($idx);
echo $zip->getCommentName('') . "\n";
echo $zip->getCommentName() . "\n";
$zip->close();
开发者ID:badlamer,项目名称:hhvm,代码行数:16,代码来源:oo_getcomment.php

示例4: exit

if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
    exit('failed');
}
$zip->addFromString('entry1.txt', 'entry #1');
$zip->addFromString('entry2.txt', 'entry #2');
$zip->addFromString('dir/entry2d.txt', 'entry #2');
$zip->addFromString('entry4.txt', 'entry #1');
$zip->addFromString('entry5.txt', 'entry #2');
var_dump($zip->setCommentName('entry1.txt', 'entry1.txt'));
var_dump($zip->setCommentName('entry2.txt', 'entry2.txt'));
var_dump($zip->setCommentName('dir/entry2d.txt', 'dir/entry2d.txt'));
var_dump($zip->setArchiveComment('archive'));
var_dump($zip->setCommentIndex(3, 'entry4.txt'));
var_dump($zip->setCommentIndex(4, 'entry5.txt'));
var_dump($zip->setArchiveComment('archive'));
if (!$zip->status == ZIPARCHIVE::ER_OK) {
    echo "failed to write zip\n";
}
$zip->close();
if (!$zip->open($file)) {
    @unlink($file);
    exit('failed');
}
var_dump($zip->getCommentIndex(0));
var_dump($zip->getCommentIndex(1));
var_dump($zip->getCommentIndex(2));
var_dump($zip->getCommentIndex(3));
var_dump($zip->getCommentIndex(4));
var_dump($zip->getArchiveComment());
$zip->close();
@unlink($file);
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:oo_setcomment.php

示例5: ZipArchive

 $output->formatOutput = true;
 $outputIndexes = $output->createElement("local_list");
 //$outputIndexes->setAttribute('mapversion','1');
 $output->appendChild($outputIndexes);
 $zip = new ZipArchive();
 while (($file = readdir($dh)) !== false) {
     $filename = $dir . $file;
     //"./test112.zip";
     //print("processing file:" . $filename . "\n");
     if ($zip->open($filename, ZIPARCHIVE::CHECKCONS) !== TRUE) {
         // echo exit("cannot open <$filename>\n");
         // print($filename . " cannot open as zip\n");
         continue;
     }
     $indexName = $file;
     $description = $zip->getCommentIndex(0);
     $stat = $zip->statIndex(0);
     $date = date('d.m.Y', $stat['mtime']);
     $size = number_format(filesize($filename) / (1024.0 * 1024.0), 1, '.', '');
     $zip->close();
     $a[] = new Download($file, $stat['mtime'], $date, $size, $description);
     $out = $output->createElement("file");
     $out->setAttribute("file", $file);
     $out->setAttribute("mtime", $stat['mtime']);
     $out->setAttribute("date", $date);
     $out->setAttribute("size", $size);
     $out->setAttribute("description", $description);
     $outputIndexes->appendChild($out);
 }
 closedir($dh);
 //echo "Writing to file";
开发者ID:epleterte,项目名称:OsmAnd-misc,代码行数:31,代码来源:list.php

示例6: loadIndexesFromDir

function loadIndexesFromDir($output, $outputIndexes, $dir, $elementName, $ftype)
{
    $local_file = basename($_SERVER['PHP_SELF']) == basename(__FILE__);
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            $zip = new ZipArchive();
            while (($file = readdir($dh)) !== false) {
                $type = $ftype;
                $filename = $dir . $file;
                //"./test112.zip";
                //print("processing file:" . $filename . "\n");
                $indexName = $file;
                $size = number_format(filesize($filename) / (1024.0 * 1024.0), 1, '.', '');
                $targetSize = $size;
                $containerSize = filesize($filename);
                $contentSize = filesize($filename);
                if (strpos($file, '.voice') !== false) {
                    $type = "voice";
                } else {
                    if (strpos($file, '.gitignore') !== false) {
                        continue;
                    }
                }
                if (endsWith($file, ".sqlitedb")) {
                    $date = date('d.m.Y', filemtime($filename));
                    $timestamp = filemtime($filename);
                    $description = str_replace("_", " ", substr($file, 0, -9));
                } else {
                    if ($zip->open($filename, ZIPARCHIVE::CHECKCONS) !== TRUE) {
                        // echo exit("cannot open <$filename>\n");
                        // print($filename . " cannot open as zip\n");
                        continue;
                    }
                    $description = $zip->getCommentIndex(0);
                    $stat = $zip->statIndex(0, ZIPARCHIVE::FL_UNCHANGED);
                    $targetSize = number_format($stat['size'] / (1024.0 * 1024.0), 1, '.', '');
                    $contentSize = $stat['size'];
                    $timestamp = $stat['mtime'];
                    $date = date('d.m.Y', $stat['mtime']);
                    $zip->close();
                }
                if ($local_file) {
                    echo 'Local : ' . $indexName . ' ' . $date . ' ' . $size . '<br>';
                }
                $out = $output->createElement($elementName);
                $outputIndexes->appendChild($out);
                $out->setAttribute("type", $type);
                $out->setAttribute("containerSize", $containerSize);
                $out->setAttribute("contentSize", $contentSize);
                $out->setAttribute("timestamp", $timestamp * 1000);
                $out->setAttribute("date", $date);
                $out->setAttribute("size", $size);
                $out->setAttribute("targetsize", $targetSize);
                $out->setAttribute("name", $indexName);
                $out->setAttribute("description", $description);
            }
            closedir($dh);
        }
    } else {
        print $dir . " not a directory!\n";
    }
}
开发者ID:epleterte,项目名称:OsmAnd-misc,代码行数:62,代码来源:download_utils.php


注:本文中的ZipArchive::getCommentIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。