Check if file to read exists.

@param string $filePath
@param string $mode

@throws FileException

@return bool
14699
public function exists(string $filePath, string $mode = self::READ_BINARY) : bool
    {
        if (self::INPUT_STREAM === $filePath) {
            return true;
        }

        if (self::READ_BINARY === $mode && ! file_exists($filePath)) {
            throw new FileException('File not found.');
        }

        return true;
    }
1251161
private boolean validateFilePath(String filePath) {
        if (filePath == null || filePath.isEmpty()) {
            throw new IllegalArgumentException("filePath must be a valid filePath within the file system.");
        }

        // Check if the filename exists as a File -- use an absolute file to ensure we have
        // a parent: even if that parent is ${user.dir} ...
        File loc = new File(filePath).getAbsoluteFile();

        return (loc.exists() || loc.getParentFile().exists());
    }
1200570
public function isUploadedFile($filePath)
    {
        // If it's a serialized one.
        if (filter_var($filePath, FILTER_VALIDATE_URL)) {
            return true;
        }

        // If it's a normal filename.
        $file = $this->getUploadDir()->getFile($this->getUserDirectoryHash() . '/' . $filePath);
        if ($file->exists()) {
            return true;
        }

        return false;
    }
1241260
public static function create($path = false, $mode = 0777) {

        if($path && !self::isFolder(dirname($path)) && self::isWritable(dirname($path))) {

            mkdir($path, $mode);

            if(Folder::isFolder($path)) {

                return true;
            }
        } 

        return false;
    }
303971
function exists(filepath) {
  const cached = existsCache.has(filepath);

  // Only return positive to allow for generated files
  if (cached) return true;

  const filepathExists = fs.existsSync(filepath);

  if (filepathExists) existsCache.add(filepath);

  return filepathExists;
}
749126
public static function fileExistsSafe(string $filePath) : bool
    {
        if ($filePath == '') {
            return false;
        }

        if (DirHelper::isDirSafe($filePath)) {
            return false;
        }

        return file_exists($filePath);
    }
544674
private function shouldExecuteFile($execOption, $noExecOption, $filePath)
    {
        if ($execOption) {
            return true;
        }

        if ($noExecOption) {
            return false;
        }

        // By default, code that is edited is executed if there was no given input file path
        return $filePath === null;
    }
1246968
public static function isValid(string $filePath): bool
    {
        return self::myFilePathParse(
            DIRECTORY_SEPARATOR,
            $filePath,
            function ($p, $d, &$e) {
                return self::myPartValidator($p, $d, $e);
            });
    }
996182
public static function readFile($filePath)
    {
        if (false === self::exists($filePath)) {
            throw new RuntimeException(sprintf('unable to find "%s"', $filePath));
        }
        if (false === $fileData = file_get_contents($filePath)) {
            throw new RuntimeException(sprintf('unable to read file "%s"', $filePath));
        }

        return $fileData;
    }
916516
protected function openFile($filePath)
    {
        if (empty($filePath)) {
            throw new \Exception('Input file not defined.');
        } elseif (!file_exists($filePath)) {
            throw new \Exception("File does not exist: {$filePath}");
        }

        $handle = @fopen($filePath, 'r');
        if (false === $handle) {
            throw new \Exception("Unable to open file for reading: {$filePath}");
        }

        return $handle;
    }
384255
public function fileExists($containerName, $fileName, $relativePath)
    {
        $fullFileName = $this->getFullFileName($containerName, $fileName, $relativePath);

        return $this->filesystem->has($fullFileName);
    }
505098
protected function getFilesStatus(string $filepath) : bool
    {
        $status     = false;
        $path       = explode('/', $filepath);

        if (empty($path[0])) {
            // Internal Path
            $site           = $path[1];
            $acceptables    = ['css', 'CSS'];
            $filename       = $path[count($path) - 1];

            // check if style file has correct extension
            $nameParts = explode('.', $filename);
            if (!in_array($nameParts[count($nameParts) - 1], $acceptables)) {
                return false;
            }

            // Getting the subfolder(s)
            $subfolders     = '';
            for ($i = 2; $i <= count($path) - 2; $i++) {
                $subfolders .= $path[$i] . '/';
            }

            $fullPath = $_SERVER['DOCUMENT_ROOT'] . '/../module/MelisSites/' . $site . '/public/' . $subfolders . $filename;
            if (is_file($fullPath) && file_exists($fullPath)) {
                return true;
            }

        } else {
            // External Path
            if (filter_var($filepath, FILTER_VALIDATE_URL)) {
                $header_response = get_headers($filepath, 1);
                if (strpos($header_response[0], "200") !== false) {
                    // File exists
                    return true;
                }
            }
        }

        return $status;
    }
1047299
public static boolean checkIfFileExists(String filePath) {
        File file = new File(filePath);// getSDCardPath(), filePath);
        return (file.exists() ? true : false);
    }
449256
public static boolean isFileExist(String filePath) {
        if (StringUtils.isEmpty(filePath)) {
            return false;
        }

        File file = new File(filePath);
        return (file.exists() && file.isFile());
    }
1072666
public function checkCreateFile($filePath)
    {
        $defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();

        if (file_exists($filePath)) {
            if (!is_writable($filePath) && !in_array($this->getPermissionUtils()->getCurrentPermission($filePath), array($defaultPermissions['file'], $defaultPermissions['dir']))) {
                return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
            }
            return true;
        }

        $pathParts = pathinfo($filePath);
        if (!file_exists($pathParts['dirname'])) {
            $dirPermission = $defaultPermissions['dir'];
            $dirPermission = is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission;

            if (!$this->mkdir($pathParts['dirname'], $dirPermission, true)) {
                throw new Error('Permission denied: unable to create a folder on the server - ' . $pathParts['dirname']);
            }
        }

        if (touch($filePath)) {
            return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
        }

        return false;
    }
798810
public function _fetchContents( $filePath, $fname = false )
    {
        if ( $fname )
            $fname .= "::_fetchContents($filePath)";
        else
            $fname = "_fetchContents($filePath)";
        $metaData = $this->_fetchMetadata( $filePath, $fname );
        // @todo Throw an exception
        if ( !$metaData )
        {
            eZDebug::writeError( "File '$filePath' does not exist while trying to fetch its contents.", __METHOD__ );
            return false;
        }

        // @todo Catch an exception
        if ( !$contents = $this->dfsbackend->getContents( $filePath ) )
        {
            eZDebug::writeError("An error occurred while reading contents of DFS://$filePath", __METHOD__ );
            return false;
        }
        return $contents;
    }
774962
public function loadFile($filepath)
    {
        $file = realpath($filepath);
        if ($file === false) {
            throw new JitException("Error, the file `'{$filepath}'` doesn't exist.");
        }
        if (!$this->_patchers) {
            require $file;
            return true;
        }

        if (!$cached = $this->cached($file)) {
            $code = file_get_contents($file);
            $timestamp = filemtime($file);

            $rewrited = $this->_patchers->process($code, $file);
            $cached = $this->cache($file, $rewrited, max($timestamp, $this->_watchedTimestamp) + 1);
        }
        $includePath = get_include_path();
        set_include_path($includePath ? $includePath . ':' . dirname($file) : dirname($file));
        require $cached;
        restore_include_path();
        return true;
    }