2012-05-06 18:25:40 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-20 16:54:12 +04:00
|
|
|
* PhpWord
|
2012-05-06 18:25:40 +02:00
|
|
|
*
|
2014-03-20 16:54:12 +04:00
|
|
|
* Copyright (c) 2014 PhpWord
|
2012-05-06 18:25:40 +02:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*
|
2014-03-20 16:54:12 +04:00
|
|
|
* @category PhpWord
|
|
|
|
|
* @package PhpWord
|
|
|
|
|
* @copyright Copyright (c) 2014 PhpWord
|
2012-05-06 18:25:40 +02:00
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
2014-03-15 16:17:05 +07:00
|
|
|
* @version 0.8.0
|
2012-05-06 18:25:40 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-03-17 20:25:30 +04:00
|
|
|
namespace PhpOffice\PhpWord\Shared;
|
|
|
|
|
|
|
|
|
|
class File
|
2012-05-06 18:25:40 +02:00
|
|
|
{
|
2013-12-11 14:45:44 -05:00
|
|
|
/**
|
|
|
|
|
* Verify if a file exists
|
|
|
|
|
*
|
|
|
|
|
* @param string $pFilename Filename
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function file_exists($pFilename)
|
|
|
|
|
{
|
2014-03-14 20:36:09 +01:00
|
|
|
// Regular file_exists
|
|
|
|
|
return file_exists($pFilename);
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
/**
|
|
|
|
|
* Returns canonicalized absolute pathname, also for ZIP archives
|
|
|
|
|
*
|
|
|
|
|
* @param string $pFilename
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function realpath($pFilename)
|
|
|
|
|
{
|
|
|
|
|
// Returnvalue
|
|
|
|
|
$returnValue = '';
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
// Try using realpath()
|
|
|
|
|
$returnValue = realpath($pFilename);
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
// Found something?
|
|
|
|
|
if ($returnValue == '' || is_null($returnValue)) {
|
2014-03-11 16:27:42 +07:00
|
|
|
$pathArray = explode('/', $pFilename);
|
2013-12-11 14:45:44 -05:00
|
|
|
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
|
|
|
|
|
for ($i = 0; $i < count($pathArray); ++$i) {
|
|
|
|
|
if ($pathArray[$i] == '..' && $i > 0) {
|
|
|
|
|
unset($pathArray[$i]);
|
|
|
|
|
unset($pathArray[$i - 1]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$returnValue = implode('/', $pathArray);
|
|
|
|
|
}
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
// Return
|
|
|
|
|
return $returnValue;
|
|
|
|
|
}
|
2012-05-06 18:25:40 +02:00
|
|
|
}
|