1 <?php declare(strict_types=1);
48 $this->file_stream = $stream;
49 $this->path = $stream->getMetadata(
'uri');
51 $this->suffix = pathinfo($this->file_name, PATHINFO_EXTENSION);
59 $this->mime_type =
'unknown';
60 if (function_exists(
'mime_content_type')) {
61 if (file_exists($this->path)) {
62 $this->mime_type = mime_content_type($this->path);
66 if (class_exists(
'finfo')) {
67 $finfo = finfo_open(FILEINFO_MIME_TYPE);
69 $this->mime_type = finfo_buffer($finfo, $this->file_stream->read(255));
70 if ($this->file_stream->isSeekable()) {
71 $this->file_stream->rewind();
74 if ($this->mime_type ===
'application/zip' && $this->suffix !==
'zip') {
85 $this->size = $this->file_stream->getSize();
87 $mb_strlen_exists = function_exists(
'mb_strlen');
89 while ($content = $this->file_stream->read(1048576)) {
90 if ($mb_strlen_exists) {
91 $this->size += mb_strlen($content,
'8bit');
93 $this->size += strlen($content);
97 if ($this->file_stream->isSeekable()) {
98 $this->file_stream->rewind();
105 $filectime = file_exists($this->path) ? filectime($this->path) :
false;
106 $this->creation_date = $filectime ? (new \DateTimeImmutable())->setTimestamp($filectime) : new \DateTimeImmutable();
111 $this->file_name = basename($this->path);
112 if ($this->file_name ===
'memory' || $this->file_name ===
'input') {
145 $suffix_with_dot =
'.' . $this->
getSuffix();
146 if (array_key_exists($suffix_with_dot, $mime_types_array)) {
147 return $mime_types_array[$suffix_with_dot];
149 return 'application/zip';
getMSFileTypeFromSuffix()
__construct(FileStream $stream, int $next_version_number, int $revision_owner_id, string $revision_title)
__construct(Container $dic, ilPlugin $plugin)
Interface FileStream The base interface for all filesystem streams.