is_file under windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tyno Gendo

    #1

    is_file under windows


    How do you normally check filetypes? I ended up resorting to
    !is_dir($file) as all other calls seem to fail so I had to assume if not
    a directory its a file, rather than specifically checking if its a file.

    I'm recursing a folder:

    <?php
    $cat_seq = 1;
    $path = "e:\\videos\\$c at_seq";
    $dh = opendir($path);
    while ($file = readdir($dh)) {
    echo filetype($file) ."<br />";
    if ( !is_dir($file) ) {
    echo $file;
    }
    }
    ?>

    Under windows, I can try is_file(), this always returns "" (nothing),
    and if I try filetype($file) (as above on the echo) I can get 'dir' for
    directories but get the following for files:

    Warning: filetype() [function.filety pe]: Lstat failed for <filename>

  • Tyno Gendo

    #2
    Re: is_file under windows

    Tyno Gendo wrote:
    Under windows, I can try is_file(), this always returns "" (nothing),
    and if I try filetype($file) (as above on the echo) I can get 'dir' for
    directories but get the following for files:
    >
    Warning: filetype() [function.filety pe]: Lstat failed for <filename>
    >
    I'm running PHP 5.2 on WinXP with Apache 2 if that helps.

    Comment

    • Tyno Gendo

      #3
      Re: is_file under windows

      Tyno Gendo wrote:
      Tyno Gendo wrote:
      >Under windows, I can try is_file(), this always returns "" (nothing),
      >and if I try filetype($file) (as above on the echo) I can get 'dir'
      >for directories but get the following for files:
      >>
      >Warning: filetype() [function.filety pe]: Lstat failed for <filename>
      >>
      >
      I'm running PHP 5.2 on WinXP with Apache 2 if that helps.
      ... I just uploaded to a linux server to test, same result. Files exist
      because i'm just recursing a directory now and printing out the names of
      things that it finds along with an is_file($file) as well, always
      returns <blank:-/

      Comment

      • Willem Bogaerts

        #4
        Re: is_file under windows

        .. I just uploaded to a linux server to test, same result. Files exist
        because i'm just recursing a directory now and printing out the names of
        things that it finds along with an is_file($file) as well, always
        returns <blank:-/

        What do you pass to the is_file() function? The full path or just the
        "basename"?

        --
        Willem Bogaerts

        Application smith
        Kratz B.V.

        Comment

        • Tyno Gendo

          #5
          Re: is_file under windows

          Willem Bogaerts wrote:
          >.. I just uploaded to a linux server to test, same result. Files exist
          >because i'm just recursing a directory now and printing out the names of
          >things that it finds along with an is_file($file) as well, always
          >returns <blank:-/
          >
          >
          What do you pass to the is_file() function? The full path or just the
          "basename"?
          >
          In this instance I have passed fullname. I could try a chdir and then
          is_file("./$file"); ?

          Comment

          • Tyno Gendo

            #6
            Re: is_file under windows (SOLVED)

            Willem Bogaerts wrote:
            >.. I just uploaded to a linux server to test, same result. Files exist
            >because i'm just recursing a directory now and printing out the names of
            >things that it finds along with an is_file($file) as well, always
            >returns <blank:-/
            >
            >
            What do you pass to the is_file() function? The full path or just the
            "basename"?
            >
            Thanks Willem,

            I changed the test code as follows and used chdir to move into the base
            directory first, then I just opened "." as the directory and checked the
            file, it works. Code as follows checking for video files in a category
            folder:

            <?php
            $cat_seq = 1;
            $path = "e:\\videos\\$c at_seq";
            chdir($path);
            $dh = opendir(".") or die('cannot open directory');
            while ($file = readdir($dh)) {
            if ( is_file($file) ) {
            echo $file;
            }
            }
            ?>

            Comment

            Working...