123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- class PHPExcel_Shared_File
- {
-
- protected static $useUploadTempDirectory = false;
-
- public static function setUseUploadTempDirectory($useUploadTempDir = false)
- {
- self::$useUploadTempDirectory = (boolean) $useUploadTempDir;
- }
-
- public static function getUseUploadTempDirectory()
- {
- return self::$useUploadTempDirectory;
- }
-
- public static function file_exists($pFilename)
- {
-
-
-
- if (strtolower(substr($pFilename, 0, 3)) == 'zip') {
-
- $zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
- $archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
- $zip = new ZipArchive();
- if ($zip->open($zipFile) === true) {
- $returnValue = ($zip->getFromName($archiveFile) !== false);
- $zip->close();
- return $returnValue;
- } else {
- return false;
- }
- } else {
-
- return file_exists($pFilename);
- }
- }
-
- public static function realpath($pFilename)
- {
-
- $returnValue = '';
-
- if (file_exists($pFilename)) {
- $returnValue = realpath($pFilename);
- }
-
- if ($returnValue == '' || ($returnValue === null)) {
- $pathArray = explode('/', $pFilename);
- 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);
- }
-
- return $returnValue;
- }
-
- public static function sys_get_temp_dir()
- {
- if (self::$useUploadTempDirectory) {
-
-
- if (ini_get('upload_tmp_dir') !== false) {
- if ($temp = ini_get('upload_tmp_dir')) {
- if (file_exists($temp)) {
- return realpath($temp);
- }
- }
- }
- }
-
-
- if (!function_exists('sys_get_temp_dir')) {
- if ($temp = getenv('TMP')) {
- if ((!empty($temp)) && (file_exists($temp))) {
- return realpath($temp);
- }
- }
- if ($temp = getenv('TEMP')) {
- if ((!empty($temp)) && (file_exists($temp))) {
- return realpath($temp);
- }
- }
- if ($temp = getenv('TMPDIR')) {
- if ((!empty($temp)) && (file_exists($temp))) {
- return realpath($temp);
- }
- }
-
-
- $temp = tempnam(__FILE__, '');
- if (file_exists($temp)) {
- unlink($temp);
- return realpath(dirname($temp));
- }
- return null;
- }
-
-
-
- return realpath(sys_get_temp_dir());
- }
- }
|