php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7396 is_dir() doesn't work
Submitted: 2000-10-22 19:12 UTC Modified: 2000-10-28 08:21 UTC
From: whit at transpect dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.0.3pl1 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: whit at transpect dot com
New email:
PHP Version: OS:

 

 [2000-10-22 19:12 UTC] whit at transpect dot com
This snippet works:

$handle=opendir($homedir); 
while ($file = readdir($handle)) {
        $retval[count($retval)] = $file; 
}                            
closedir($handle);           
sort($retval);                             
$cnt=count($retval);
echo "CNT: $cnt";
$int=0;
while($int<$cnt) {
        if(!is_dir($retval[$int])) {
                echo "File: $retval[$int]<br>";
        } else {  
                echo "Dir: $retval[$int]<br>";
        }
        $int++;
}

But if I change "if(!is_dir($retval[$int])) {" to "if(is_file($retval[$int])) {" it fails.

The way it fails is that all of the files fail to match as files, and are shown prefixed by "Dir:".

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-23 03:49 UTC] jmcastagnetto@php.net
I could not reproduce the bug with a modified code, main difference is that I am using the full path in the is_file() function, as it should be. Code below works on PHP 4.0.3pl1 (RedHat 6.1 and Solaris 2.6):

$dir ="/path/to/phpdoc/en";
$handle=opendir($dir);
while ($file = readdir($handle)) {
    $retval[count($retval)] = $dir."/".$file; 
}                            
closedir($handle);           
sort($retval);                             
$cnt=count($retval);
echo "CNT: $cnt\n";
$int=0;
while($int<$cnt) {
  if(is_file($retval[$int])) {
          echo "File: ".$retval[$int]."\n";
  } else {  
          echo "Dir: ".$retval[$int]."\n";
  }
  $int++;
}


 [2000-10-27 08:12 UTC] sniper@php.net
Please check the example Jesus gave. And report back whether it 
solves this or not.

--Jani
 [2000-10-28 08:21 UTC] jmcastagnetto@php.net
I received an e-mail fromn whit@transpect.com to the effect that the code changes I made fixed the problem he had.

Closing this bug report now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC