PHPExcel_Shared
[ class tree: PHPExcel_Shared ] [ index: PHPExcel_Shared ] [ all elements ]

Source for file File.php

Documentation is available at File.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2011 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Shared
  23.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.6, 2011-02-27
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Shared_File
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Shared
  34.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. {
  37.     /**
  38.       * Verify if a file exists
  39.       *
  40.       * @param     string    $pFilename    Filename
  41.       * @return bool 
  42.       */
  43.     public static function file_exists($pFilename{
  44.         // Sick construction, but it seems that
  45.         // file_exists returns strange values when
  46.         // doing the original file_exists on ZIP archives...
  47.         if strtolower(substr($pFilename03)) == 'zip' {
  48.             // Open ZIP file and verify if the file exists
  49.             $zipFile         substr($pFilename6strpos($pFilename'#'6);
  50.             $archiveFile     substr($pFilenamestrpos($pFilename'#'1);
  51.  
  52.             $zip new ZipArchive();
  53.             if ($zip->open($zipFile=== true{
  54.                 $returnValue ($zip->getFromName($archiveFile!== false);
  55.                 $zip->close();
  56.                 return $returnValue;
  57.             else {
  58.                 return false;
  59.             }
  60.         else {
  61.             // Regular file_exists
  62.             return file_exists($pFilename);
  63.         }
  64.     }
  65.  
  66.     /**
  67.      * Returns canonicalized absolute pathname, also for ZIP archives
  68.      *
  69.      * @param string $pFilename 
  70.      * @return string 
  71.      */
  72.     public static function realpath($pFilename{
  73.         // Returnvalue
  74.         $returnValue '';
  75.  
  76.         // Try using realpath()
  77.         if (file_exists($pFilename)) {
  78.             $returnValue realpath($pFilename);
  79.         }
  80.  
  81.         // Found something?
  82.         if ($returnValue == '' || is_null($returnValue)) {
  83.             $pathArray explode('/' $pFilename);
  84.             while(in_array('..'$pathArray&& $pathArray[0!= '..'{
  85.                 for ($i 0$i count($pathArray)++$i{
  86.                     if ($pathArray[$i== '..' && $i 0{
  87.                         unset($pathArray[$i]);
  88.                         unset($pathArray[$i 1]);
  89.                         break;
  90.                     }
  91.                 }
  92.             }
  93.             $returnValue implode('/'$pathArray);
  94.         }
  95.  
  96.         // Return
  97.         return $returnValue;
  98.     }
  99.  
  100.     /**
  101.      * Get the systems temporary directory.
  102.      *
  103.      * @return string 
  104.      */
  105.     public static function sys_get_temp_dir()
  106.     {
  107.         // sys_get_temp_dir is only available since PHP 5.2.1
  108.         // http://php.net/manual/en/function.sys-get-temp-dir.php#94119
  109.  
  110.         if !function_exists('sys_get_temp_dir')) {
  111.             if ($temp getenv('TMP') ) {
  112.                 if (file_exists($temp)) return realpath($temp)}
  113.             }
  114.             if ($temp getenv('TEMP') ) {
  115.                 if (file_exists($temp)) return realpath($temp)}
  116.             }
  117.             if ($temp getenv('TMPDIR') ) {
  118.                 if (file_exists($temp)) return realpath($temp)}
  119.             }
  120.  
  121.             // trick for creating a file in system's temporary dir
  122.             // without knowing the path of the system's temporary dir
  123.             $temp tempnam(__FILE__'');
  124.             if (file_exists($temp)) {
  125.                 unlink($temp);
  126.                 return realpath(dirname($temp));
  127.             }
  128.  
  129.             return null;
  130.         }
  131.  
  132.         // use ordinary built-in PHP function
  133.         //    There should be no problem with the 5.2.4 Suhosin realpath() bug, because this line should only
  134.         //        be called if we're running 5.2.1 or earlier
  135.         return realpath(sys_get_temp_dir());
  136.     }
  137.  
  138. }

Documentation generated on Sun, 27 Feb 2011 16:31:30 -0800 by phpDocumentor 1.4.3