You are here

public function PHPExcel_Shared_ZipArchive::getFromName in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/ZipArchive.php \PHPExcel_Shared_ZipArchive::getFromName()

Extract file from archive by given fileName (Emulate ZipArchive getFromName())

Parameters

string $fileName Filename for the file in zip archive:

Return value

string $contents File string contents

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/ZipArchive.php, line 141

Class

PHPExcel_Shared_ZipArchive
PHPExcel_Shared_ZipArchive

Code

public function getFromName($fileName) {
  $list = $this->_zip
    ->listContent();
  $listCount = count($list);
  $list_index = -1;
  for ($i = 0; $i < $listCount; ++$i) {
    if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
      $list_index = $i;
      break;
    }
  }
  $extracted = "";
  if ($list_index != -1) {
    $extracted = $this->_zip
      ->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
  }
  else {
    $filename = substr($fileName, 1);
    $list_index = -1;
    for ($i = 0; $i < $listCount; ++$i) {
      if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
        $list_index = $i;
        break;
      }
    }
    $extracted = $this->_zip
      ->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
  }
  if (is_array($extracted) && $extracted != 0) {
    $contents = $extracted[0]["content"];
  }
  return $contents;
}