You are here

public function PHPExcel_Reader_OOCalc::canRead in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/OOCalc.php \PHPExcel_Reader_OOCalc::canRead()

* Can the current PHPExcel_Reader_IReader read the file? * *

Parameters

string $pFilename: * @return boolean * @throws PHPExcel_Reader_Exception

Overrides PHPExcel_Reader_Abstract::canRead

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/OOCalc.php, line 70

Class

PHPExcel_Reader_OOCalc
PHPExcel_Reader_OOCalc

Code

public function canRead($pFilename) {

  // Check if file exists
  if (!file_exists($pFilename)) {
    throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  }
  $zipClass = PHPExcel_Settings::getZipClass();

  // Check if zip class exists
  //		if (!class_exists($zipClass, FALSE)) {
  //			throw new PHPExcel_Reader_Exception($zipClass . " library is not enabled");
  //		}
  $mimeType = 'UNKNOWN';

  // Load file
  $zip = new $zipClass();
  if ($zip
    ->open($pFilename) === true) {

    // check if it is an OOXML archive
    $stat = $zip
      ->statName('mimetype');
    if ($stat && $stat['size'] <= 255) {
      $mimeType = $zip
        ->getFromName($stat['name']);
    }
    elseif ($stat = $zip
      ->statName('META-INF/manifest.xml')) {
      $xml = simplexml_load_string($this
        ->securityScan($zip
        ->getFromName('META-INF/manifest.xml')), 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
      $namespacesContent = $xml
        ->getNamespaces(true);
      if (isset($namespacesContent['manifest'])) {
        $manifest = $xml
          ->children($namespacesContent['manifest']);
        foreach ($manifest as $manifestDataSet) {
          $manifestAttributes = $manifestDataSet
            ->attributes($namespacesContent['manifest']);
          if ($manifestAttributes->{'full-path'} == '/') {
            $mimeType = (string) $manifestAttributes->{'media-type'};
            break;
          }
        }
      }
    }
    $zip
      ->close();
    return $mimeType === 'application/vnd.oasis.opendocument.spreadsheet';
  }
  return FALSE;
}