is_subdir

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • André Hänsel

    is_subdir

    Hi,

    is there a function like is_subdir in PHP?

    It's not, is it?

    Is there a way to achieve its functionality (which is probably clearly
    explained by its name ;)) in PHP?

    Regards,
    André

  • Chung Leong

    #2
    Re: is_subdir


    André Hänsel wrote:
    Hi,
    >
    is there a function like is_subdir in PHP?
    >
    It's not, is it?
    >
    Is there a way to achieve its functionality (which is probably clearly
    explained by its name ;)) in PHP?
    >
    Regards,
    André
    If you mean a function that tells you whether a directory is a
    sub-directory in another, that answer is no. You can approximate it
    from getting the absolute path of both with realpath() and then compare
    them.

    Comment

    • André Hänsel

      #3
      Re: is_subdir

      Chung Leong schrieb:
      André Hänsel wrote:
      is there a function like is_subdir in PHP?
      >
      If you mean a function that tells you whether a directory is a
      sub-directory in another, that answer is no. You can approximate it
      from getting the absolute path of both with realpath() and then compare
      them.
      Unfortunately this doesn't work. When I have such a structure...
      /
      |-- collection
      | `-- dir -/dir
      `-- dir
      `-- subdir

      ....then /collection/dir/subdir is a subdir of /collection but the
      realpath solution says no, because it dereferences the symlinks.

      Regards,
      André

      Comment

      • ImOk

        #4
        Re: is_subdir

        is_dir ("./mysubdir/mysubsubdir" )

        or Windows

        is_dir (".\\mysubdir\\ mysubsubdir" )

        .. means the current working directory.

        Chung Leong wrote:
        André Hänsel wrote:
        Hi,

        is there a function like is_subdir in PHP?

        It's not, is it?

        Is there a way to achieve its functionality (which is probably clearly
        explained by its name ;)) in PHP?

        Regards,
        André
        >
        If you mean a function that tells you whether a directory is a
        sub-directory in another, that answer is no. You can approximate it
        from getting the absolute path of both with realpath() and then compare
        them.

        Comment

        • André Hänsel

          #5
          Re: is_subdir

          ImOk schrieb:
          is_dir ("./mysubdir/mysubsubdir" )
          That only determines if ./mysubdir/mysubsubdir is a directory. It makes
          no statement about whether it is a subdirectory of another directory.

          is_dir('../../nosubdir) will return true (if the dir exits, of course),
          although it is no subdir of the working dir.

          Comment

          • Mel

            #6
            Re: is_subdir

            On 2006-07-10 03:49:12 +1000, "André Hänsel" <andre@webkr.de said:
            ImOk schrieb:
            >is_dir ("./mysubdir/mysubsubdir" )
            >
            That only determines if ./mysubdir/mysubsubdir is a directory. It makes
            no statement about whether it is a subdirectory of another directory.
            >
            is_dir('../../nosubdir) will return true (if the dir exits, of course),
            although it is no subdir of the working dir.
            Wouldn't you just try to open it as a directory from the context of the
            parent and if it opens, then it's a subdir?

            Comment

            • André Hänsel

              #7
              Re: is_subdir

              Mel schrieb:
              On 2006-07-10 03:49:12 +1000, "André Hänsel" <andre@webkr.de said:
              >
              ImOk schrieb:
              is_dir ("./mysubdir/mysubsubdir" )
              That only determines if ./mysubdir/mysubsubdir is a directory. It makes
              no statement about whether it is a subdirectory of another directory.

              is_dir('../../nosubdir) will return true (if the dir exits, of course),
              although it is no subdir of the working dir.
              >
              Wouldn't you just try to open it as a directory from the context of the
              parent and if it opens, then it's a subdir?
              If there were no ".."s in the world, that would work.
              I would have to get some kind of temporary chroot, but that would
              probably also dereference the symlinks.

              But another idea:
              There connot be an escaped slash in a path, can it?
              What does a path like "dir\/subdir" mean?
              a) a subdirectory of the current path named "dir/subdir"
              b) a directory named "dir\" with a subdirectory named "subdir"
              I think, it's answer b.

              If that is true, it will be safe to just explode the path by "/",
              traverse it and convert every "." to nothing and every ".." to "go one
              step up" (if I am not already in /).

              Right?

              Comment

              • ImOk

                #8
                Re: is_subdir

                I am totally confused by this thread. What in the world are you trying
                to do?
                In my experience of development when the code starts getting weird,
                then the original premise must be re-evaluated. Maybe you can write the
                logic in pseudocode and post it here.

                André Hänsel wrote:
                Mel schrieb:
                On 2006-07-10 03:49:12 +1000, "André Hänsel" <andre@webkr.de said:
                ImOk schrieb:
                >is_dir ("./mysubdir/mysubsubdir" )
                >
                That only determines if ./mysubdir/mysubsubdir is a directory. It makes
                no statement about whether it is a subdirectory of another directory.
                >
                is_dir('../../nosubdir) will return true (if the dir exits, of course),
                although it is no subdir of the working dir.
                Wouldn't you just try to open it as a directory from the context of the
                parent and if it opens, then it's a subdir?
                >
                If there were no ".."s in the world, that would work.
                I would have to get some kind of temporary chroot, but that would
                probably also dereference the symlinks.
                >
                But another idea:
                There connot be an escaped slash in a path, can it?
                What does a path like "dir\/subdir" mean?
                a) a subdirectory of the current path named "dir/subdir"
                b) a directory named "dir\" with a subdirectory named "subdir"
                I think, it's answer b.
                >
                If that is true, it will be safe to just explode the path by "/",
                traverse it and convert every "." to nothing and every ".." to "go one
                step up" (if I am not already in /).

                Right?

                Comment

                Working...