5
* Copyright (c) 2006 - 2009 PHPExcel
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.
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.
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
22
* @package PHPExcel_Shared
23
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
24
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
* @version 1.7.0, 2009-08-10
30
* PHPExcel_Shared_File
33
* @package PHPExcel_Shared
34
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
36
class PHPExcel_Shared_File
39
* Verify if a file exists
41
* @param string $pFilename Filename
44
public static function file_exists($pFilename) {
45
// Sick construction, but it seems that
46
// file_exists returns strange values when
47
// doing the original file_exists on ZIP archives...
48
if ( strtolower(substr($pFilename, 0, 3)) == 'zip' ) {
49
// Open ZIP file and verify if the file exists
50
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
51
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
53
$zip = new ZipArchive();
54
if ($zip->open($zipFile) === true) {
55
$returnValue = ($zip->getFromName($archiveFile) !== false);
62
// Regular file_exists
63
return file_exists($pFilename);
68
* Returns canonicalized absolute pathname, also for ZIP archives
70
* @param string $pFilename
73
public static function realpath($pFilename) {
77
// Try using realpath()
78
$returnValue = realpath($pFilename);
81
if ($returnValue == '' || is_null($returnValue)) {
82
$pathArray = split('/' , $pFilename);
83
while(in_array('..', $pathArray) && $pathArray[0] != '..') {
84
for ($i = 0; $i < count($pathArray); ++$i) {
85
if ($pathArray[$i] == '..' && $i > 0) {
86
unset($pathArray[$i]);
87
unset($pathArray[$i - 1]);
92
$returnValue = implode('/', $pathArray);