From fcf26436095fe8a6b3ba83f4263a6b7036ba5cf7 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Fri, 26 Nov 2010 00:36:01 +0000 Subject: [PATCH] Additional validation check in the canLoad() method of Excel2007 Reader to return false for OpenXML documents that aren't workbooks (eg. pptx, docx) git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@64373 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Reader/Excel2007.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 10efeaa7..187966b7 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -168,18 +168,26 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); } + $xl = false; // Load file $zip = new ZipArchive; if ($zip->open($pFilename) === true) { // check if it is an OOXML archive $rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); + foreach ($rels->Relationship as $rel) { + switch ($rel["Type"]) { + case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument": + if (basename($rel["Target"]) == 'workbook.xml') { + $xl = true; + } + break; + } + } $zip->close(); - - return ($rels !== false); } - return false; + return $xl; } private function _castToBool($c) {