Source for file File.php
Documentation is available at File.php
* Copyright (c) 2006 - 2011 PHPExcel
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.6, 2011-02-27
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* Verify if a file exists
* @param string $pFilename Filename
// Sick construction, but it seems that
// file_exists returns strange values when
// doing the original file_exists on ZIP archives...
// Open ZIP file and verify if the file exists
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
if ($zip->open($zipFile) === true) {
$returnValue = ($zip->getFromName($archiveFile) !== false);
* Returns canonicalized absolute pathname, also for ZIP archives
* @param string $pFilename
public static function realpath($pFilename) {
if ($returnValue == '' || is_null($returnValue)) {
$pathArray = explode('/' , $pFilename);
while(in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++ $i) {
if ($pathArray[$i] == '..' && $i > 0) {
unset ($pathArray[$i - 1]);
$returnValue = implode('/', $pathArray);
* Get the systems temporary directory.
// sys_get_temp_dir is only available since PHP 5.2.1
// http://php.net/manual/en/function.sys-get-temp-dir.php#94119
if ($temp = getenv('TEMP') ) {
if ($temp = getenv('TMPDIR') ) {
// trick for creating a file in system's temporary dir
// without knowing the path of the system's temporary dir
// use ordinary built-in PHP function
// There should be no problem with the 5.2.4 Suhosin realpath() bug, because this line should only
// be called if we're running 5.2.1 or earlier
|