From f1b146bb617bedb2802f83308d9151868c63f6ac Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 27 Aug 2020 15:30:45 -0400 Subject: [PATCH] Add PagefilesManager::hasFile() method --- wire/core/PagefilesManager.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/wire/core/PagefilesManager.php b/wire/core/PagefilesManager.php index 6056f262..8f568509 100644 --- a/wire/core/PagefilesManager.php +++ b/wire/core/PagefilesManager.php @@ -495,6 +495,27 @@ class PagefilesManager extends Wire { return $has; } + /** + * Does given Page have the given file? Checks in a silent manner, not creating anything. + * + * @param Page $page + * @param string $file Filename (basename) excluding path + * @param bool $getPathname Return the full pathname to the file (rather than true) if it exists? (default=false) + * @return bool|string + * @since 3.0.166 + * + */ + static public function hasFile(Page $page, $file, $getPathname = false) { + $path = self::_path($page); + if(!is_dir($path)) return false; + $file = basename($file); + $file = str_replace(array('\\', '/', '..'), '', $file); + $pathname = $path . $file; + if(!file_exists($pathname)) return false; + if($getPathname) return $pathname; + return true; + } + /** * Get the files path for a given page (whether it exists or not). *