php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25846 is_dir() does not work on any folder other than the current directory
Submitted: 2003-10-12 18:49 UTC Modified: 2003-10-12 20:55 UTC
From: notepad at codewalkers dot com Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 4.3.4RC1 OS: winXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: notepad at codewalkers dot com
New email:
PHP Version: OS:

 

 [2003-10-12 18:49 UTC] notepad at codewalkers dot com
Description:
------------
say you have the folder "test" and inside "test" you have:
- images (folder)
- the_following_code.php (file)

inside the "images" folder you have some sub directories. the_following_code will NEVER return true.

if i use !is_dir instead, it then returns the sub directories as files instead of folders. this appears to have been an ongoing problem, perhaps overlooked or under-explained.

Reproduce code:
---------------
function directory($dir)
{
    $mydir = opendir($dir);
    while(false !== ($file = readdir($mydir)))
    {
        if($file != "." && $file != "..")
        {
            if(is_dir($file))
                echo "$file<br>\r\n";
            elseif(is_dir($mydir.$file))
                echo "$file<br>\r\n";
            elseif(is_dir($mydir.$file.'/'))
                echo "$file<br>\r\n";
        }
    }
    closedir($mydir);
}
$path = '/inetpub/wwwroot/Scripts/test/images/';
directory($path);

Expected result:
----------------
i expect a list of sub dirs..

Actual result:
--------------
i get nothing.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-12 19:47 UTC] wez@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

readdir() returns only the basename of the filenames, not the full path. You need to manually concatentate the directory name to the filename.
 [2003-10-12 19:57 UTC] notepad at codewalkers dot com
the code above DOES concatentate the directory name to the filename
 [2003-10-12 20:38 UTC] sniper@php.net
No you don't, you're appending a resource, 
RTFM: http://www.php.net/opendir

resource opendir ( string path)



 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 21:01:30 2024 UTC