problem checking of a file is a file or a directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    problem checking of a file is a file or a directory

    Dear friends ,

    I am using window os . i face a problem is that

    [PHP]

    $file="D:\Domai ns\\naturetrail sindia.info\www root\html\\";
    $file=$path."\h tml\\";
    $d = dir($file);

    while (false !== ($entry = $d->read())) {
    $typ = filetype($entry );
    if($typ == "dir"){
    print '<li>[d]:'.$entry.'</li>';
    }else if($typ == "file"){
    $topic=explode( ".",$entry) ;
    // $tname=$topic." .html";
    if($topic[0] <> "") {
    print '<li><input type="checkbox" name="check[]" value="'.$topic[0].'"><a href="edit.php? f='.$topic[0].'">'.$topic[0].'</a></li>';
    }
    }else{
    print '<li>Unknown document type</li>';
    }
    }
    $d->close();

    ?>
    [/PHP]


    problem is above code is its not check wethere $typ is file or directory
    plz tell me how i can do that ?
    and whats error in above code


    sanjay
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    What do you get from this?
    [PHP]filetype($entry )[/PHP]

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      You might try something similar to this:
      [code=php]

      function fileordir($what )
      {
      if(is_file($wha t)) return 'file';
      else if(is_dir($what )) return 'dir';
      else return 'nothing';
      }
      [/code]

      Comment

      • sanjay123456
        New Member
        • Sep 2006
        • 125

        #4
        dear motoma ,

        now i am using following code ......


        [PHP]

        $file=$path."\h tml\\";
        $d = dir($file);
        echo $file."<br/>";
        while (false !== ($entry = $d->read())) {
        echo $entry;
        $typ = is_dir($entry);
        echo $typ;
        if($typ){
        print '<li>[d]:'.$entry.'</li>';
        }else if(!$typ){
        $topic=explode( ".",$entry) ;
        // $tname=$topic." .html";
        if($topic[0] <> "") {
        print '<li><input type="checkbox" name="check[]" value="'.$topic[0].'"><a href="edit.php? f='.$topic[0].'">'.$topic[0].'</a></li>';
        }
        }else{
        echo "unknown";
        }
        }
        $d->close();

        ?>

        [/PHP]


        but in this case its print single dot and double dot directory and
        if html folder having some directory then its print as a file
        is_dir function not checking properly .....
        now what i am do ?


        sanjay

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          I believe:
          $file=$path."\h tml\\";
          is an error.

          I think it should be:
          $file=$path."\\ html\\";

          Comment

          Working...