ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Shared\File Class Reference
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Shared\File:

Static Public Member Functions

static setUseUploadTempDirectory ($useUploadTempDir)
 Set the flag indicating whether the File Upload Temp directory should be used for temporary files. More...
 
static getUseUploadTempDirectory ()
 Get the flag indicating whether the File Upload Temp directory should be used for temporary files. More...
 
static fileExists ($pFilename)
 Verify if a file exists. More...
 
static realpath ($pFilename)
 Returns canonicalized absolute pathname, also for ZIP archives. More...
 
static sysGetTempDir ()
 Get the systems temporary directory. More...
 
static temporaryFilename ()
 
static assertFile ($filename)
 Assert that given path is an existing file and is readable, otherwise throw exception. More...
 

Static Protected Attributes

static $useUploadTempDirectory = false
 

Detailed Description

Definition at line 9 of file File.php.

Member Function Documentation

◆ assertFile()

static PhpOffice\PhpSpreadsheet\Shared\File::assertFile (   $filename)
static

◆ fileExists()

static PhpOffice\PhpSpreadsheet\Shared\File::fileExists (   $pFilename)
static

Verify if a file exists.

Parameters
string$pFilenameFilename
Returns
bool

Definition at line 45 of file File.php.

46 {
47 // Sick construction, but it seems that
48 // file_exists returns strange values when
49 // doing the original file_exists on ZIP archives...
50 if (strtolower(substr($pFilename, 0, 3)) == 'zip') {
51 // Open ZIP file and verify if the file exists
52 $zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
53 $archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
54
55 $zip = new ZipArchive();
56 if ($zip->open($zipFile) === true) {
57 $returnValue = ($zip->getFromName($archiveFile) !== false);
58 $zip->close();
59
60 return $returnValue;
61 }
62
63 return false;
64 }
65
66 return file_exists($pFilename);
67 }

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xlsx\ContentTypes\getImageMimeType().

+ Here is the caller graph for this function:

◆ getUseUploadTempDirectory()

static PhpOffice\PhpSpreadsheet\Shared\File::getUseUploadTempDirectory ( )
static

Get the flag indicating whether the File Upload Temp directory should be used for temporary files.

Returns
bool Use File Upload Temporary directory (true or false)

Definition at line 33 of file File.php.

References PhpOffice\PhpSpreadsheet\Shared\File\$useUploadTempDirectory.

◆ realpath()

static PhpOffice\PhpSpreadsheet\Shared\File::realpath (   $pFilename)
static

Returns canonicalized absolute pathname, also for ZIP archives.

Parameters
string$pFilename
Returns
string

Definition at line 76 of file File.php.

77 {
78 // Returnvalue
79 $returnValue = '';
80
81 // Try using realpath()
82 if (file_exists($pFilename)) {
83 $returnValue = realpath($pFilename);
84 }
85
86 // Found something?
87 if ($returnValue == '' || ($returnValue === null)) {
88 $pathArray = explode('/', $pFilename);
89 while (in_array('..', $pathArray) && $pathArray[0] != '..') {
90 $iMax = count($pathArray);
91 for ($i = 0; $i < $iMax; ++$i) {
92 if ($pathArray[$i] == '..' && $i > 0) {
93 unset($pathArray[$i], $pathArray[$i - 1]);
94
95 break;
96 }
97 }
98 }
99 $returnValue = implode('/', $pathArray);
100 }
101
102 // Return
103 return $returnValue;
104 }
static realpath($pFilename)
Returns canonicalized absolute pathname, also for ZIP archives.
Definition: File.php:76
$i
Definition: disco.tpl.php:19

References $i, and PhpOffice\PhpSpreadsheet\Shared\File\realpath().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xlsx\getFromZipArchive(), PhpOffice\PhpSpreadsheet\Shared\File\realpath(), and PhpOffice\PhpSpreadsheet\Shared\File\sysGetTempDir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUseUploadTempDirectory()

static PhpOffice\PhpSpreadsheet\Shared\File::setUseUploadTempDirectory (   $useUploadTempDir)
static

Set the flag indicating whether the File Upload Temp directory should be used for temporary files.

Parameters
bool$useUploadTempDirUse File Upload Temporary directory (true or false)

Definition at line 23 of file File.php.

23 : void
24 {
25 self::$useUploadTempDirectory = (bool) $useUploadTempDir;
26 }

◆ sysGetTempDir()

static PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir ( )
static

Get the systems temporary directory.

Returns
string

Definition at line 111 of file File.php.

112 {
113 if (self::$useUploadTempDirectory) {
114 // use upload-directory when defined to allow running on environments having very restricted
115 // open_basedir configs
116 if (ini_get('upload_tmp_dir') !== false) {
117 if ($temp = ini_get('upload_tmp_dir')) {
118 if (file_exists($temp)) {
119 return realpath($temp);
120 }
121 }
122 }
123 }
124
125 return realpath(sys_get_temp_dir());
126 }

References PhpOffice\PhpSpreadsheet\Shared\File\realpath().

Referenced by PhpOffice\PhpSpreadsheet\Shared\XMLWriter\__construct(), PhpOffice\PhpSpreadsheet\Writer\Pdf\__construct(), and PhpOffice\PhpSpreadsheet\Writer\Html\writeChartInCell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ temporaryFilename()

static PhpOffice\PhpSpreadsheet\Shared\File::temporaryFilename ( )
static

Definition at line 128 of file File.php.

128 : string
129 {
130 $filename = tempnam(self::sysGetTempDir(), 'phpspreadsheet');
131 if ($filename === false) {
132 throw new Exception('Could not create temporary file');
133 }
134
135 return $filename;
136 }

References $filename.

Field Documentation

◆ $useUploadTempDirectory

PhpOffice\PhpSpreadsheet\Shared\File::$useUploadTempDirectory = false
staticprotected

The documentation for this class was generated from the following file: