Pchp.Library.Streams.PhpStream.CheckAccess C# (CSharp) Method

CheckAccess() public static method

Performs all checks on a path passed to a PHP function.

This method performs a check similar to safe_mode.c: php_checkuid_ex() together with open_basedir check.

The filename may be one of the following: A relative path. The path is resolved regarding the include_path too if required and checking continues as in the next case. An absolute path. The file or directory is checked for existence and for access permissions1 according to the given mode. 1 Regarding the open_basedir configuration option. File access permissions are checked at the time of file manipulation (opening, copying etc.).

If the file can not be accessed /// and the is not set.
public static CheckAccess ( string filename, CheckAccessMode mode, CheckAccessOptions options ) : bool
filename string A resolved path. Must be an absolute path to a local file.
mode CheckAccessMode One of the .
options CheckAccessOptions true to suppress error messages.
return bool
        public static bool CheckAccess(string filename, CheckAccessMode mode, CheckAccessOptions options)
        {
            Debug.Assert(Path.IsPathRooted(filename));
            string url = FileSystemUtils.StripPassword(filename);
            bool quiet = (options & CheckAccessOptions.Quiet) > 0;

            switch (mode)
            {
                case CheckAccessMode.FileMayExist:
                    break;

                case CheckAccessMode.FileExists:
                    if (!File.Exists(filename))
                    {
                        if (!quiet) PhpException.Throw(PhpError.Warning, ErrResources.stream_file_not_exists, url);
                        return false;
                    }
                    break;

                case CheckAccessMode.FileNotExists:
                    if (File.Exists(filename))
                    {
                        if (!quiet) PhpException.Throw(PhpError.Warning, ErrResources.stream_file_exists, url);
                        return false;
                    }
                    break;

                case CheckAccessMode.FileOrDirectory:
                    if ((!Directory.Exists(filename)) && (!File.Exists(filename)))
                    {
                        if (!quiet) PhpException.Throw(PhpError.Warning, ErrResources.stream_path_not_exists, url);
                        return false;
                    }
                    break;

                case CheckAccessMode.Directory:
                    if (!Directory.Exists(filename))
                    {
                        if (!quiet) PhpException.Throw(PhpError.Warning, ErrResources.stream_directory_not_exists, url);
                        return false;
                    }
                    break;

                default:
                    Debug.Assert(false);
                    return false;
            }

            return true;
        }