From 82085aa8c30b6d3995113e81438c0dc5d5188e17 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 4 Feb 2024 10:16:34 +0200 Subject: [PATCH] add getMimeByPath method --- README.md | 12 ++++++++++++ src/Dokuwiki/Filesystem.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index c8ca921..31bff03 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,18 @@ var_dump ( ); ``` +#### Filesystem::getMimeByPath + +Return file MIME if path match storage item + +``` +var_dump ( + $filesystem->getMimeByPath( + '/full/path/to/page.txt' + ) +); +``` + #### Filesystem::getDataByPath Return file content if path match storage item diff --git a/src/Dokuwiki/Filesystem.php b/src/Dokuwiki/Filesystem.php index c132624..77fdc21 100644 --- a/src/Dokuwiki/Filesystem.php +++ b/src/Dokuwiki/Filesystem.php @@ -187,6 +187,18 @@ class Filesystem return $path; } + public function getMimeByPath(?string $path): ?string + { + if (in_array($path, $this->_list) && is_file($path) || is_readable($path)) + { + return mime_content_type( + $path + ); + } + + return null; + } + public function getDataByPath(?string $path): ?string { if (in_array($path, $this->_list) && is_file($path) || is_readable($path))