title: Why am I getting an "invalid or unitialized Zip object" error when trying to read excel file via PHP?
body: <p>I would like to find out how to <strong>read</strong> an excel file using via PHP.  My specific use case is using <a href="http://phpexcel.codeplex.com/" rel="noreferrer">PHPExcel</a> from within Yii.</p>
  
  <p>I have followed numerous tutorials and I am always stuck at one point: "ZipArchive::getFromName(): Invalid or unitialized Zip object". I have added the extensions, loader, etc.  but nothing seems to be working. is there any way around this? or do I need to get another library? Here is the code in my controller.</p>
  
  <pre class="lang-php prettyprint-override"><code>Yii::import('application.vendors.PHPExcel.PHPExcel',true);
  $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  $objPHPExcel = $objReader-&gt;load('c:\cctv.xls'); //$file --&gt; your filepath and filename
  $objWorksheet = $objPHPExcel-&gt;getActiveSheet();
  $highestRow = $objWorksheet-&gt;getHighestRow(); // e.g. 10
  $highestColumn = $objWorksheet-&gt;getHighestColumn(); // e.g 'F'
  $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5
  echo '&lt;table&gt;' . "\n";
  for ($row = 2; $row &lt;= $highestRow; ++$row) {
    echo '&lt;tr&gt;' . "\n";
    for ($col = 0; $col &lt;= $highestColumnIndex; ++$col) {
      echo '&lt;td&gt;' . $objWorksheet-&gt;getCellByColumnAndRow($col, $row)-&gt;getValue() . '&lt;/td&gt;' . "\n";
    }
    echo '&lt;/tr&gt;' . "\n";
  }
  echo '&lt;/table&gt;' . "\n";
  </code></pre>
  
  <p>this is the detailed error:</p>
  
  <p>C:\wamp\www\example\protected\vendors\PHPExcel\PHPExcel\Reader\Excel2007.php(272)</p>
  
  <pre class="lang-php prettyprint-override"><code>}
   public function _getFromZipArchive(ZipArchive $archive, $fileName = '')
   {
       // Root-relative paths
       if (strpos($fileName, '//') !== false)
       {
           $fileName = substr($fileName, strpos($fileName, '//') + 1);
       }
       $fileName = PHPExcel_Shared_File::realpath($fileName);
  
       // Apache POI fixes
       $contents = $archive-&gt;getFromName($fileName);
       if ($contents === false)
       {
           $contents = $archive-&gt;getFromName(substr($fileName, 1));
       }
  
       /*
       if (strpos($contents, '&lt;?xml') !== false &amp;&amp; strpos($contents, '&lt;?xml') !== 0)
       {
           $contents = substr($contents, strpos($contents, '&lt;?xml'));
       }
       var_dump($fileName);
       var_dump($contents);
  </code></pre>
  
  <p>Stack Trace  C:\wamp\www\trunk\protected\vendors\PHPExcel\PHPExcel\Reader\Excel2007.php(272): ZipArchive->getFromName("_rels/.rels")</p>
  
  <pre class="lang-php prettyprint-override"><code>$fileName = substr($fileName, strpos($fileName, '//') + 1);
  }
  $fileName = PHPExcel_Shared_File::realpath($fileName);
  // Apache POI fixes
  $contents = $archive-&gt;getFromName($fileName);
  if ($contents === false)
  {
      $contents = $archive-&gt;getFromName(substr($fileName, 1));
  }
  </code></pre>
  
  <p>C:\wamp\www\example\protected\vendors\PHPExcel\PHPExcel\Reader\Excel2007.php(312): PHPExcel_Reader_Excel2007->_getFromZipArchive(ZipArchive, "_rels/.rels")</p>
  
  <pre class="lang-php prettyprint-override"><code>$excel-&gt;removeCellXfByIndex(0); // remove the default style
       }
       $zip = new ZipArchive;
       $zip-&gt;open($pFilename);
  
       $rels = simplexml_load_string($this-&gt;_getFromZipArchive($zip, "_rels/.rels")); //~http://schemas.openxmlformats.org/package/2006/relationships");
       foreach ($rels-&gt;Relationship as $rel) {
           switch ($rel["Type"]) {
               case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
                   $xmlCore = simplexml_load_string($this-&gt;_getFromZipArchive($zip, "{$rel['Target']}"));
                   if (is_object($xmlCore)) {
  </code></pre>
  
  <p>C:\wamp\www\example\protected\controllers\AdminController.php(58): PHPExcel_Reader_Excel2007->load("c:\cctv.xls")</p>
  
  <pre class="lang-php prettyprint-override"><code>public function actionCreateSource() {
  Yii::import('application.vendors.PHPExcel.PHPExcel',true);
  $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  $objPHPExcel = $objReader-&gt;load('c:\cctv.xls'); //$file --&gt; your filepath and filename
  $objWorksheet = $objPHPExcel-&gt;getActiveSheet();
  $highestRow = $objWorksheet-&gt;getHighestRow(); // e.g. 10
  $highestColumn = $objWorksheet-&gt;getHighestColumn(); // e.g 'F'
  $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5
  echo '&lt;table&gt;' . "\n";
  </code></pre>