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


PHP ZipArchive::getStream方法代码示例

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


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

示例1: unpack_player_archive

function unpack_player_archive($player_package)
{
    if (!class_exists("ZipArchive")) {
        return zip_fallback($player_package);
    }
    $zip = new ZipArchive();
    if ($zip->open($player_package)) {
        $contents = "";
        $dir = $zip->getNameIndex(0);
        $fp = $zip->getStream($dir . "player.swf");
        if (!$fp) {
            return READ_ERROR;
        }
        while (!feof($fp)) {
            $contents .= fread($fp, 2);
        }
        fclose($fp);
        $result = @file_put_contents(LongTailFramework::getPrimaryPlayerPath(), $contents);
        if (!$result) {
            return WRITE_ERROR;
        }
        chmod(LongTailFramework::getPrimaryPlayerPath(), 0777);
        $contents = "";
        $fp = $zip->getStream($dir . "yt.swf");
        if (!$fp) {
            return READ_ERROR;
        }
        while (!feof($fp)) {
            $contents .= fread($fp, 2);
        }
        fclose($fp);
        $result = @file_put_contents(str_replace("player.swf", "yt.swf", LongTailFramework::getPrimaryPlayerPath()), $contents);
        if (!$result) {
            return WRITE_ERROR;
        }
        chmod(str_replace("player.swf", "yt.swf", LongTailFramework::getPrimaryPlayerPath()), 0777);
        $fp = $zip->getStream($dir . "jwplayer.js");
        if ($fp) {
            $contents = "";
            while (!feof($fp)) {
                $contents .= fread($fp, 2);
            }
            fclose($fp);
            $result = @file_put_contents(LongTailFramework::getEmbedderPath(), $contents);
            if (!$result) {
                return WRITE_ERROR;
            }
            chmod(LongTailFramework::getEmbedderPath(), 0777);
        }
        $zip->close();
    }
    unlink($player_package);
    return SUCCESS;
}
开发者ID:thejimbirch,项目名称:unionrockyards,代码行数:54,代码来源:UpdatePage.php

示例2: doCreate

 protected function doCreate()
 {
     $result = true;
     $counter = 0;
     foreach ($this->metaData['createdFiles'] as $createdFile) {
         $fullName = "{$this->basePath}/{$createdFile}";
         if ($this->matchesTargetHash($createdFile)) {
             $counter++;
         } elseif (!is_dir(dirname($fullName)) && !mkdir(dirname($fullName), 0777, true)) {
             $this->messages[] = "Failed to create directories for {$createdFile}";
             $result = false;
         } elseif (file_exists($fullName)) {
             $this->messages[] = "File to be created: {$createdFile} already exists.";
             $result = false;
         } elseif (false === ($handle = @fopen($fullName, 'x'))) {
             $this->messages[] = "No write permission: {$createdFile}";
             $result = false;
         } else {
             $this->archive->getStream($createdFile);
             stream_copy_to_stream($this->archive->getStream($createdFile), $handle);
             fclose($handle);
             if (!$this->matchesTargetHash($createdFile)) {
                 $this->messages[] = "{$createdFile} was not successfully created.";
             } else {
                 $counter++;
             }
         }
     }
     $this->messages[] = "{$counter} files created.";
     return $result;
 }
开发者ID:sam-it,项目名称:php-auto-update,代码行数:31,代码来源:Update.php

示例3: 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");
     }
 }
开发者ID:GulfCoastGreens,项目名称:gavoters,代码行数:31,代码来源:ImportGeorgiaCommand.php

示例4: 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.');
     }
 }
开发者ID:JarvusInnovations,项目名称:Emergence-preview,代码行数:29,代码来源:EmergenceIO.class.php

示例5: 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;
                }
            }
        }
    }
}
开发者ID:palpandi111,项目名称:mbeddr.core,代码行数:25,代码来源:repo.php

示例6: getFileHandler

 /**
  * Get a file handler to the entry defined by its name.
  *
  * @param string $name The name of the entry to use.
  *
  * @return resource|bool File pointer (resource) on success or false on failure.
  * @throws Exception
  */
 public function getFileHandler($name)
 {
     if (!$this->open) {
         throw new \Exception('No archive has been opened');
     }
     return $this->zip->getStream($name);
 }
开发者ID:gitter-badger,项目名称:recanalyst,代码行数:15,代码来源:Archive.php

示例7: createFromArchive

 /** Returns an array of strings (for error messages) and image objects (for successful). */
 public static function createFromArchive($filename, $objAlbum)
 {
     if (!class_exists('ZipArchive')) {
         return "image_nozip";
     }
     $arrRet = array();
     $zipArchive = new ZipArchive();
     $zipArchive->open($filename);
     for ($i = 0; $i < $zipArchive->numFiles; $i++) {
         /* We stat the file, to get its name. */
         $stat = $zipArchive->statIndex($i);
         $strInName = $stat['name'];
         /* Open the temp output file. This is vulnerable to a race condition. TODO. */
         $filename = tempnam("/tmp", "OSPAP2");
         $out = fopen($filename, 'w');
         /* Get the file stream from the archive. */
         $in = $zipArchive->getStream($stat['name']);
         /* Read the file from the zip. It takes several iterations to get to the end, so we loop. */
         while (!feof($in)) {
             fputs($out, fgets($in));
         }
         /* Close the input and output files. */
         fclose($out);
         fclose($in);
         /* Determine the mimetype from the filename. None of php's built-in functions seem to work.. */
         if (preg_match("/\\.png\$/", $stat['name'])) {
             $mimetype = "image/png";
         } elseif (preg_match("/\\.gif\$/", $stat['name'])) {
             $mimetype = "image/gif";
         } elseif (preg_match("/\\.jpg\$/", $stat['name'])) {
             $mimetype = "image/jpeg";
         } elseif (preg_match("/\\.jpeg\$/", $stat['name'])) {
             $mimetype = "image/jpeg";
         } else {
             $mimetype = "unknown";
         }
         /* Create the new file. */
         $new = clsPicture::createFromFile($filename, $mimetype, $objAlbum);
         /* Delete the file. */
         unlink($filename);
         if (is_string($new)) {
             $strError = $new;
             $new = new clsDB('image');
             $new->set('error', $strError);
             $new->set('name', $stat['name']);
         } else {
             $new->set('original_name', $stat['name']);
             $new->set('original_mime', $mimetype);
             $new->set('original_size', $stat['size']);
         }
         /* Add it to the array (note that it can be a string (for an error) or an image object. */
         $arrRet[] = $new;
     }
     if (sizeof($arrRet) == 0) {
         return 'image_nofiles';
     }
     return $arrRet;
 }
开发者ID:shifter,项目名称:ospap2,代码行数:59,代码来源:clsPicture.php

示例8: getFileContentFromArchive

function getFileContentFromArchive(ZipArchive $archive, $filename)
{
    $fp = $archive->getStream($filename);
    $contents = '';
    while (!feof($fp)) {
        $contents .= fread($fp, 4096);
    }
    fclose($fp);
    return $contents;
}
开发者ID:pombredanne,项目名称:tuleap,代码行数:10,代码来源:collect_xml_data.php

示例9: getZipContentOfFile

function getZipContentOfFile($zipFilePath, $name)
{
    $zip = new ZipArchive();
    $zip->open($zipFilePath);
    $fp = $zip->getStream($name);
    $contents = '';
    while (!feof($fp)) {
        $contents .= fread($fp, 1024);
    }
    fclose($fp);
    return $contents;
}
开发者ID:eurofurence,项目名称:ef-app_backend,代码行数:12,代码来源:helpers.php

示例10: mergecitem

function mergecitem($item, $t1, $c, $sc)
{
    $czip = 'D:\\Projects\\zhunei-wechat\\web\\bible\\b\\' . getHexStr($t1) . '\\' . getHexStr($c) . '.zip';
    echo $czip . '<br/>';
    $curitem = $item;
    $lastsitem = null;
    $zip = new ZipArchive();
    if ($zip->open($czip)) {
        $i = 0;
        while (true) {
            $fname = dechex($i);
            if (strlen($fname) < 2) {
                $fname = '0' . $fname;
            }
            $contents = '';
            $fp = $zip->getStream($fname);
            if (!$fp) {
                break;
            }
            while (!feof($fp)) {
                $contents .= fread($fp, 2);
            }
            fclose($fp);
            $sitem = null;
            while (true) {
                $curitem = $curitem->nextSibling->nextSibling;
                $class = $curitem->getAttribute('class');
                if ($class == 'c') {
                    break;
                } else {
                    if ($class == 's') {
                        $sitem = $curitem;
                        break;
                    }
                }
            }
            if ($sitem) {
                $sitem->removeChild($sitem->firstChild);
                $sitem->appendChild(new DOMText(zhconversion_hans($contents)));
                $sitem->setAttribute('value', $i + 1);
                $lastsitem = $sitem;
            } else {
                $sitem = $lastsitem->parentNode->insertBefore(new DOMElement('p'), $lastsitem->nextSibling->nextSibling);
                $sitem->setAttribute('class', 's');
                $sitem->setAttribute('value', $i + 1);
                $sitem->appendChild(new DOMText(zhconversion_hans($contents)));
            }
            //			echo(($i+1).'&nbsp;&nbsp;'.zhconversion_hans($contents).'&nbsp;'.$sitem->textContent.'<br/>');
            $i++;
        }
    }
    //	die();
}
开发者ID:gaoerjun,项目名称:Web,代码行数:53,代码来源:merge.php

示例11: getContent

 /**
  * @inheritDoc
  */
 public function getContent($path)
 {
     $content = '';
     $fp = $this->zip->getStream($path);
     if (!$fp) {
         throw new FileException(sprintf('File "%s" not found in archive.', $path));
     }
     while (!feof($fp)) {
         $content .= fread($fp, 2);
     }
     fclose($fp);
     return $content;
 }
开发者ID:MPParsley,项目名称:xconnect,代码行数:16,代码来源:ZipFile.php

示例12: __construct

 public function __construct($zipFilename)
 {
     $zip = new \ZipArchive();
     $zip->open($zipFilename);
     if ($zip->numFiles != 1) {
         throw new \Exception("Unknown source file structure");
     }
     $filename = $zip->getNameIndex(0);
     $this->handle = $zip->getStream($filename);
     if (!$this->handle) {
         throw new \Exception("Could not read source");
     }
 }
开发者ID:tangervu,项目名称:finzip,代码行数:13,代码来源:Resource.php

示例13: getFileContent

 /**
  * @param  string                                     $pathToFile
  * @return null|string
  * @throws \Thelia\Exception\FileNotFoundException
  * @throws \Thelia\Exception\FileNotReadableException
  * @throws \ErrorException
  *
  * This method returns a file content
  */
 public function getFileContent($pathToFile)
 {
     $pathToFile = $this->formatFilePath($pathToFile);
     if (!$this->hasFile($pathToFile)) {
         $this->throwFileNotFound($pathToFile);
     }
     $stream = $this->zip->getStream($pathToFile);
     $content = "";
     while (!feof($stream)) {
         $content .= fread($stream, 2);
     }
     fclose($stream);
     return $content;
 }
开发者ID:margery,项目名称:thelia,代码行数:23,代码来源:ZipArchiveBuilder.php

示例14: extractByRoot

 /**
  * @param string $path
  * @param string $targetDir
  * @param string $root path without trailing slash
  * @return boolean
  */
 static function extractByRoot($path, $targetDir, $root)
 {
     //get items paths from within root
     $namesList = srokap_zip::getArchiveNameIndex($path);
     if ($namesList === false) {
         throw new IOException("Error while reading archive contents: {$path}");
     }
     foreach ($namesList as $key => $item) {
         //keep only items within root path
         if (strpos($item, $root) !== 0) {
             unset($namesList[$key]);
         }
     }
     if (empty($namesList)) {
         throw new IOException("Invalid archive root path privided: {$root}");
     }
     $targetDir .= '/';
     if (!srokap_files::createDir($targetDir)) {
         throw new IOException("Unable to create target dir: {$targetDir}");
     }
     $result = false;
     $zip = new ZipArchive();
     if ($zip->open($path)) {
         foreach ($namesList as $key => $item) {
             $sufix = substr($item, strlen($root) + 1);
             if ($sufix === false) {
                 continue;
             }
             $path = $targetDir . $sufix;
             $dirPath = dirname($path);
             if (!empty($dirPath) && !srokap_files::createDir($dirPath)) {
                 throw new IOException("Unable to create dir: " . dirname($path));
             }
             if ($item[strlen($item) - 1] == '/') {
                 //not a file
                 continue;
             }
             $content = stream_get_contents($zip->getStream($item));
             if ($content === false) {
                 throw new IOException("Error reading from archive path: {$item}");
             }
             if (file_put_contents($path, $content) === false) {
                 throw new IOException("Error extracting file from {$item} to {$path}");
             }
         }
         $result = true;
     }
     $zip->close();
     return $result;
 }
开发者ID:socialweb,项目名称:PiGo,代码行数:56,代码来源:srokap_zip.php

示例15: ShowAllImageInZip

function ShowAllImageInZip($path, $filename)
{
    ignore_user_abort(true);
    set_time_limit(0);
    // disable the time limit for this script
    $dl_file = $filename;
    $fullPath = $path . $dl_file;
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "zip":
            break;
        default:
            exit;
    }
    //echo "this is zip ok <br/>";
    $zip = new ZipArchive();
    if ($zip->open($fullPath) === true) {
        for ($i = 0; $i < $zip->numFiles; $i++) {
            //$zip->extractTo('path/to/extraction/', array($zip->getNameIndex($i)));
            // here you can run a custom function for the particular extracted file
            $cont_name = $zip->getNameIndex($i);
            $cont_path_parts = pathinfo($cont_name);
            $cont_ext = strtolower($cont_path_parts["extension"]);
            if ($cont_ext == "jpg") {
                $contents = '';
                //echo $cont_name."<br/>";
                $fp = $zip->getStream($cont_name);
                if (!$fp) {
                    exit("failed\n");
                }
                //echo "get stream...<br/>";
                while (!feof($fp)) {
                    $contents .= fread($fp, 2);
                }
                fclose($fp);
                $b64 = base64_encode($contents);
                list($w, $h) = getimagesizefromstring($contents);
                //echo $w." ".$h."<br/>";
                list($width, $height) = fixWidth(600, $w, $h);
                //echo $width." ".$height."<br/>";
                echo "<img src='data:image/jpeg;base64,{$b64}' width='" . $width . "' height='" . $height . "'><br/>";
            }
        }
        $zip->close();
    } else {
        echo "fail open file " . $filename . "<br/>";
    }
}
开发者ID:Acoross-Product,项目名称:Php_ComicsArchive,代码行数:49,代码来源:ShowAllImageInZip.php


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