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


PHP ZipArchive::setCommentName方法代码示例

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


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

示例1: ZipArchive

<?php

$z = new ZipArchive();
$z->open('test_with_comment.zip');
// Add "Foo Comment" as comment for the foo entry
$z->setCommentName('foo', 'Too Comment ' . time());
$z->close();
开发者ID:cefalo19,项目名称:php-src,代码行数:7,代码来源:comment.php

示例2: run


//.........这里部分代码省略.........
             }
             $type = false;
             $signature = '';
             $finfo = new finfo(FILEINFO_MIME_TYPE);
             if ($options['file'] && $options['file'] != '-') {
                 if (!file_exists($options['file'])) {
                     $this->fail($options['file'] . ': Cannot open file');
                 }
                 if (!$bk->upload($options['file'])) {
                     $this->fail('Unable to upload file contents to backend');
                 }
                 $type = $finfo->file($options['file']);
                 list(, $signature) = AttachmentFile::_getKeyAndHash($options['file'], true);
             } else {
                 $stream = fopen('php://stdin', 'rb');
                 while ($block = fread($stream, $bk->getBlockSize())) {
                     if (!$bk->write($block)) {
                         $this->fail('Unable to send file contents to backend');
                     }
                     if (!$type) {
                         $type = $finfo->buffer($block);
                     }
                 }
                 if (!$bk->flush()) {
                     $this->fail('Unable to commit file contents to backend');
                 }
             }
             // TODO: Update file metadata
             $sql = 'UPDATE ' . FILE_TABLE . ' SET bk=' . db_input($bk->getBkChar()) . ', created=CURRENT_TIMESTAMP' . ', type=' . db_input($type) . ', signature=' . db_input($signature) . ' WHERE id=' . db_input($f->getId());
             if (!db_query($sql) || db_affected_rows() != 1) {
                 $this->fail('Unable to update file metadata');
             }
             $this->stdout->write("Successfully saved contents\n");
             break;
         case 'migrate':
             if (!$options['to']) {
                 $this->fail('Please specify a target backend for migration');
             }
             if (!FileStorageBackend::isRegistered($options['to'])) {
                 $this->fail('Target backend is not installed. See `backends` action');
             }
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             $count = 0;
             foreach ($files as $m) {
                 $f = AttachmentFile::lookup($m->id);
                 if ($f->getBackend() == $options['to']) {
                     continue;
                 }
                 if ($options['verbose']) {
                     $this->stdout->write('Migrating ' . $m->name . "\n");
                 }
                 try {
                     if (!$f->migrate($options['to'])) {
                         $this->stderr->write('Unable to migrate ' . $m->name . "\n");
                     } else {
                         $count++;
                     }
                 } catch (IOException $e) {
                     $this->stderr->write('IOError: ' . $e->getMessage());
                 }
             }
             $this->stdout->write("Migrated {$count} files\n");
             break;
         case 'export':
             // Create a temporary ZIP file
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             if (!$options['file']) {
                 $this->fail('Please specify zip file with `-f`');
             }
             $zip = new ZipArchive();
             if (true !== ($reason = $zip->open($options['file'], ZipArchive::CREATE))) {
                 $this->fail($reason . ': Unable to create zip file');
             }
             $manifest = array();
             foreach ($files as $m) {
                 $f = AttachmentFile::lookup($m->id);
                 $zip->addFromString($f->getId(), $f->getData());
                 $zip->setCommentName($f->getId(), $f->getName());
                 // TODO: Log %attachment and %ticket_attachment entries
                 $info = array('file' => $f->getInfo());
                 foreach ($m->tickets as $t) {
                     $info['tickets'][] = $t->ht;
                 }
                 $manifest[$f->getId()] = $info;
             }
             $zip->addFromString('MANIFEST', serialize($manifest));
             $zip->close();
             break;
         case 'expunge':
             // Create a temporary ZIP file
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             foreach ($files as $f) {
                 $f->tickets->expunge();
                 $f->unlink() && $f->delete();
             }
     }
 }
开发者ID:dmiguel92,项目名称:osTicket-1.8,代码行数:101,代码来源:file.php

示例3: ZipArchive

   $zip = new ZipArchive();
   $zipfilename = $safe_name . ".cbz";
   if ($zip->open($zipfilename, ZIPARCHIVE::CREATE) !== TRUE) {
       exit("cannot open <{$zipfilename}>\n");
   }
   $manifest = '';
   foreach ($contents as $filepath => $file) {
       // Traditional CBZ have all files in the root,
       // but that explodes if unpacked. Retain the folder inside the package.
       $innerfilename = $file['filename'];
       if ($use_subfolder) {
           $innerfilename = $safe_name . '/' . $file['filename'];
       }
       $zip->addFile($filepath, $innerfilename);
       $manifest .= "{$innerfilename}, '{$file['url']}'\n";
       $zip->setCommentName($innerfilename, $file['url']);
   }
   $zipinfo = '{
 "appID":"cbzget/001",
 "lastModified":"' . date("Y-m-d h:i:s O") . '",
 "ComicBookInfo/1.0":{
   "title":"' . $page_title . '",
   "series":"' . $original_url->host . '",
   "publisher":"' . $original_url . '",
   "url":"' . $original_url . '",
   "publicationYear":' . date('Y') . ',
   "publicationMonth":' . date('n') . ',
   "tags":["Downloads"]
 }}';
   $zip->addFromString("ZipInfo.txt", $zipinfo);
   $zip->addFromString("manifest.txt", $manifest);
开发者ID:Ecgogetem,项目名称:dmans-utilities,代码行数:31,代码来源:cbzget.sh.php

示例4: dirname

<?php

$dirname = dirname(__FILE__) . '/';
include $dirname . 'utils.inc';
$file = $dirname . '__tmp_oo_set_comment.zip';
@unlink($file);
$zip = new ZipArchive();
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));
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:oo_setcomment.php


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