Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
FileInfo Class Reference

Public Member Functions

 __construct (Filesystem $filesystem, Mime $mime)
 
 getMimeType ($fileName)
 
 getStat ($fileName)
 
 isExist ($fileName)
 
 isBeginsWithMediaDirectoryPath ($fileName)
 

Data Fields

const ENTITY_MEDIA_PATH = '/catalog/category'
 

Detailed Description

Class FileInfo

Provides information about requested file

Definition at line 19 of file FileInfo.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Filesystem  $filesystem,
Mime  $mime 
)
Parameters
Filesystem$filesystem
Mime$mime

Definition at line 50 of file FileInfo.php.

53  {
54  $this->filesystem = $filesystem;
55  $this->mime = $mime;
56  }

Member Function Documentation

◆ getMimeType()

getMimeType (   $fileName)

Retrieve MIME type of requested file

Parameters
string$fileName
Returns
string

Definition at line 91 of file FileInfo.php.

92  {
93  $filePath = $this->getFilePath($fileName);
94  $absoluteFilePath = $this->getMediaDirectory()->getAbsolutePath($filePath);
95 
96  $result = $this->mime->getMimeType($absoluteFilePath);
97  return $result;
98  }
$fileName
Definition: translate.phtml:15

◆ getStat()

getStat (   $fileName)

Get file statistics data

Parameters
string$fileName
Returns
array

Definition at line 106 of file FileInfo.php.

107  {
108  $filePath = $this->getFilePath($fileName);
109 
110  $result = $this->getMediaDirectory()->stat($filePath);
111  return $result;
112  }
$fileName
Definition: translate.phtml:15

◆ isBeginsWithMediaDirectoryPath()

isBeginsWithMediaDirectoryPath (   $fileName)

Checks for whether $fileName string begins with media directory path

Parameters
string$fileName
Returns
bool

Definition at line 159 of file FileInfo.php.

160  {
161  $filePath = ltrim($fileName, '/');
162 
163  $mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath();
164  $isFileNameBeginsWithMediaDirectoryPath = strpos($filePath, $mediaDirectoryRelativeSubpath) === 0;
165 
166  return $isFileNameBeginsWithMediaDirectoryPath;
167  }
$fileName
Definition: translate.phtml:15

◆ isExist()

isExist (   $fileName)

Check if the file exists

Parameters
string$fileName
Returns
bool

Definition at line 120 of file FileInfo.php.

121  {
122  $filePath = $this->getFilePath($fileName);
123 
124  $result = $this->getMediaDirectory()->isExist($filePath);
125  return $result;
126  }
$fileName
Definition: translate.phtml:15

Field Documentation

◆ ENTITY_MEDIA_PATH

const ENTITY_MEDIA_PATH = '/catalog/category'

Path in /pub/media directory

Definition at line 24 of file FileInfo.php.


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