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

Assert that given path is an existing file and is readable, otherwise throw exception.

Parameters
string$filename

Definition at line 143 of file File.php.

References $filename.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Ods\canRead(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\canRead(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\canRead(), PhpOffice\PhpSpreadsheet\Reader\Xls\canRead(), PhpOffice\PhpSpreadsheet\IOFactory\createReaderForFile(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\getFromZipArchive(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Ods\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Xml\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Xls\listWorksheetInfo(), PhpOffice\PhpSpreadsheet\Reader\Ods\listWorksheetNames(), PhpOffice\PhpSpreadsheet\Reader\Xlsx\listWorksheetNames(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\listWorksheetNames(), PhpOffice\PhpSpreadsheet\Reader\Xml\listWorksheetNames(), PhpOffice\PhpSpreadsheet\Reader\Xls\listWorksheetNames(), PhpOffice\PhpSpreadsheet\Reader\Ods\load(), PhpOffice\PhpSpreadsheet\Reader\Xml\load(), PhpOffice\PhpSpreadsheet\Reader\Gnumeric\loadIntoExisting(), PhpOffice\PhpSpreadsheet\Reader\BaseReader\openFile(), and PhpOffice\PhpSpreadsheet\Shared\OLERead\read().

143  : void
144  {
145  if (!is_file($filename)) {
146  throw new InvalidArgumentException('File "' . $filename . '" does not exist.');
147  }
148 
149  if (!is_readable($filename)) {
150  throw new InvalidArgumentException('Could not open "' . $filename . '" for reading.');
151  }
152  }
$filename
Definition: buildRTE.php:89
+ Here is the caller graph for this function:

◆ 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.

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

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  }
+ 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.

34  {
35  return self::$useUploadTempDirectory;
36  }

◆ 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.

References $i.

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

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
+ 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.

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

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

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  }
static realpath($pFilename)
Returns canonicalized absolute pathname, also for ZIP archives.
Definition: File.php:76
+ 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.

References $filename.

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  }
$filename
Definition: buildRTE.php:89

Field Documentation

◆ $useUploadTempDirectory

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

Definition at line 16 of file File.php.


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