From 0dbe6b5ab455a27628b82addc37253b01a05a39f Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 22 Dec 2016 15:17:05 +0000 Subject: [PATCH] file : add the methods is_readable, is_writeable, is_executable git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3332 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- file.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/file.php b/file.php index 2792273..98d2584 100644 --- a/file.php +++ b/file.php @@ -265,6 +265,50 @@ class file return false; } + /** Tells whether a file exists and is writeable + * @param string $filename The filename to test + * @return bool true if the $filename is a file exists and is writeable + * @throws If parent directory not exists, or is not executable + */ + public function is_executable ($filename) + { + $this->debug (2, "is_executable ($filename)"); + $filename = $this->realpath ($filename); + $this->checkPathRO (dirname ($filename)); + if (file_exists ($filename) && is_executable ($filename)) + return true; + return false; + } + + /** Tells whether a file exists and is readable + * @param string $filename The filename to test + * @return bool true if the $filename is a file exists and is readable + * @throws If parent directory not exists, or is not executable + */ + public function is_readable ($filename) + { + $this->debug (2, "is_readable ($filename)"); + $filename = $this->realpath ($filename); + $this->checkPathRO (dirname ($filename)); + if (file_exists ($filename) && is_readable ($filename)) + return true; + return false; + } + + /** Tells whether a file exists and is writeable + * @param string $filename The filename to test + * @return bool true if the $filename is a file exists and is writeable + * @throws If parent directory not exists, or is not executable + */ + public function is_writeable ($filename) + { + $this->debug (2, "is_writeable ($filename)"); + $filename = $this->realpath ($filename); + $this->checkPathRO (dirname ($filename)); + if (file_exists ($filename) && is_writeable ($filename)) + return true; + return false; + } /** Lock a file exclusively * @param string $filename The file to lock