Retrive the folder name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maheswaran
    New Member
    • Mar 2007
    • 190

    Retrive the folder name

    HI,

    See the sample

    $basedir = C:\Documents and Settings

    $fileuploadpath =C:\Documents and Settings\folder 1\folder2\abcd. jpg
    (or)

    $fileuploadpath =C:\Documents and Settings\folder 1\folder2\abcd. jpg

    I want to retrieve the name of folder1 or/and folder2 between the $basedir and $fileuploadpath ....

    How can i find ? (May number of folders come between $basedir,$fileu ploadpath)
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    [CODE=php]$directories = explode("/", str_replace($_S ERVER['DOCUMENT_ROOT']."/", "", str_replace("\\ ","/",getcwd()) ));
    print_r($direct ories);[/CODE]

    See if you want this.

    Comment

    • maheswaran
      New Member
      • Mar 2007
      • 190

      #3
      sorry where i give my $fileuploadpath ... If am given in $_SERVER[Document_root]...Is not work just am getting like this

      "C:Program Filesxampphtdoc sprojectfolderi mport"

      Comment

      • maheswaran
        New Member
        • Mar 2007
        • 190

        #4
        Am getting $basedir and $fileuploadpath while uploading a file

        I want to retrieve the name of folder1 or/and folder2 between the $basedir and $fileuploadpath ....


        like

        basedir: C:/document
        fileuploadpath: C:/document/foldernamesampl e/upload.gif

        i want retrive only the foldernamesampl e

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by maheswaran
          Am getting $basedir and $fileuploadpath while uploading a file

          I want to retrieve the name of folder1 or/and folder2 between the $basedir and $fileuploadpath ....


          like

          basedir: C:/document
          fileuploadpath: C:/document/foldernamesampl e/upload.gif

          i want retrive only the foldernamesampl e
          [php]
          <?php
          $loc = str_replace("\\ ", "/", $_SERVER['SCRIPT_FILENAM E']);

          $parts = explode("/", $loc);

          echo $parts[count($parts) - 2];
          ?>
          [/php]

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Like Markus' example shows,
            Using the explode() function to split a file path on the / char (or \ on Windows), all the resulting elements except the first and last would be folder names. You would just have to point to the element you need.

            Comment

            • maheswaran
              New Member
              • Mar 2007
              • 190

              #7
              Thanks.But if case like this
              C:/document/foldernamesampl e1/upload.gif
              C:/document/foldernamesampl e1//foldernamesampl e2/upload.gif
              C:/document/foldernamesampl e1//foldernamesampl e2/foldernamesampl e3/upload.gif

              Then it's not work.. That am said above any number of folders come between basedir and fileuploadpath. ..

              Comment

              Working...