is_file() fails on actual files, why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

    is_file() fails on actual files, why?

    Code snippet:

    if (!($dirID = opendir($ACTUAL _STARTPATH . '/content/')) && $hasCookie) {
    $html .= $font . '<font color=cc0000><l i>Could not open files in content
    folder</li></font></font><p>';
    } else if ($hasCookie) {

    clearstatcache( ); // CLEAR THE STATUS CACHE FOR is_file() TO PROPERLY
    DETERMINE FILE STATUS
    $html .= $font . 'Contents: <p>';
    while (($file = readdir($dirID) ) !== false) {
    if (is_file($file) || !preg_match('/^\./', $file)) {
    $html .= "\n<br><a href=/content/" . substr($file, strrpos('/', $file),
    strlen($file)) .
    '>' . substr($file, strrpos('/', $file), strlen($file)) .
    "</a><p>\n";
    }
    }
    }

    where $ACTUAL_STARTPA TH is the actual path for each file. However, whenever
    I try to check to see if a read file is an actual file and not either a
    directory, '.' nor '..', it constantly skips every legitimate file! These
    files have extensions of .html, .txt, .doc, .pdf, etc.

    Is is_dir() then a failed PHP command?

    Phil


  • Andy Hassall

    #2
    Re: is_file() fails on actual files, why?

    On Mon, 18 Aug 2003 02:43:07 -0400, "Phil Powell" <soazine@erols. com>
    wrote:
    [color=blue]
    >Code snippet:
    >
    >if (!($dirID = opendir($ACTUAL _STARTPATH . '/content/')) && $hasCookie) {
    > $html .= $font . '<font color=cc0000><l i>Could not open files in content
    >folder</li></font></font><p>';
    > } else if ($hasCookie) {
    >
    > clearstatcache( ); // CLEAR THE STATUS CACHE FOR is_file() TO PROPERLY
    >DETERMINE FILE STATUS
    > $html .= $font . 'Contents: <p>';
    > while (($file = readdir($dirID) ) !== false) {
    > if (is_file($file) || !preg_match('/^\./', $file)) {[/color]

    readdir returns filenames only, not paths. You're getting is_file to
    look at the wrong directory, unless the current directory happens to
    be the one you're scanning with opendir.

    Comment

    • Phil Powell

      #3
      Re: is_file() fails on actual files, why?

      That wasn't the problem; the problem was that the files were of permission
      0700 along with the folder. It was physically unable to open the directory,
      much less the files. I gave up on a PHP solution and wrote it in TCL CGI
      and it works.

      Thanx though
      Phil

      "Andy Hassall" <andy@andyh.co. uk> wrote in message
      news:9uf1kvsfvb pfgehmuthl1m9fo 7ilumit6v@4ax.c om...[color=blue]
      > On Mon, 18 Aug 2003 02:43:07 -0400, "Phil Powell" <soazine@erols. com>
      > wrote:
      >[color=green]
      > >Code snippet:
      > >
      > >if (!($dirID = opendir($ACTUAL _STARTPATH . '/content/')) && $hasCookie) {
      > > $html .= $font . '<font color=cc0000><l i>Could not open files in[/color][/color]
      content[color=blue][color=green]
      > >folder</li></font></font><p>';
      > > } else if ($hasCookie) {
      > >
      > > clearstatcache( ); // CLEAR THE STATUS CACHE FOR is_file() TO PROPERLY
      > >DETERMINE FILE STATUS
      > > $html .= $font . 'Contents: <p>';
      > > while (($file = readdir($dirID) ) !== false) {
      > > if (is_file($file) || !preg_match('/^\./', $file)) {[/color]
      >
      > readdir returns filenames only, not paths. You're getting is_file to
      > look at the wrong directory, unless the current directory happens to
      > be the one you're scanning with opendir.
      >[/color]


      Comment

      Working...