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