#22499 [Bgs->Opn]: is_dir doesn't always work
| From: | itamarc at rogers dot com | Date: | Fri, 18 Apr 2003 21:00:26 +0000 |
| Subject: | #22499 [Bgs->Opn]: is_dir doesn't always work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-37866@lists.php.net to get a copy of this message | ||
ID: 22499
User updated by: itamarc at rogers dot com
Reported By: itamarc at rogers dot com
-Status: Bogus
+Status: Open
Bug Type: Directory function related
Operating System: windows xp
PHP Version: 4.3.1
New Comment:
new info has been found. I'm reopening this bug from bogus.
Previous Comments:
------------------------------------------------------------------------
[2003-04-17 16:47:35] mark_ford_uk at yahoo dot co dot uk
(currently using php4.2.2)
I too have discovered directories are not always recognised,. However,
I have found they are correctly recognised provided I ensure the path
has a '/' on the end.
This bug appears to be widely reported and to my knowledge has not been
fixed even in recent versions. Can someone please investigate?
Thanks.
------------------------------------------------------------------------
[2003-03-02 19:05:36] msopacua@php.net
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.
Thank you for your interest in PHP.
Next time: make the script shorter, please! We don't need the size
stuff.
IIC - when the first entry is a directory it will always fail, because
you only change dirs after you read a file.
Make the test:
if(!is_dir("$dir/$entry"))
and you'll see it'll always work.
------------------------------------------------------------------------
[2003-03-02 16:21:37] itamarc at rogers dot com
let's see. using apache2 on win xp pro
<?
if (!empty($_GET['directory'])) {
$temp = $_GET['directory'];
$d = dir("d:/inetpub/wwwroot/$temp");
$old = $_GET['old'];
} else {
$d = dir("d:/inetpub/wwwroot");
$old = "";
}
echo "<h3>Path: ".$d->path."</h3><br>\n";
$dir = $d->path;
$totaldirsize = 0;
$mark = 1;
print "<table width=\"100%\"><tr><td
width=\"10%\"><u>File
Name:</u></td><td><u>File Size:</u></td></tr>\n";
print "<tr><td colspan=2><hr></td></tr>\n";
while (false !== ($entry = $d->read())) {
if (!is_dir($entry)) {
chdir($dir);
$file = filesize($entry);
$totaldirsize = $totaldirsize + $file;
if ($file > 1023) {
$file = $file / 1024;
$mark++;
if ($file > 1023) {
$file = $file / 1024;
$mark++;
if ($file > 1023) {
$file = $file / 1024;
$mark++;
}
}
}
$file = round($file, 3);
print "<tr><td><a
href=\"$dir/$entry\">$entry</a></td>\n";
if ($mark == 1)
print "<td>$file Bytes</td></tr>\n";
elseif ($mark == 2)
print "<td>$file KBytes</td></tr>\n";
elseif ($mark == 3)
print "<td>$file MBytes</td></tr>\n";
elseif ($mark == 4)
print "<td>$file GBytes</td></tr>\n";
else
print "<td>\"$file\" \"$mark\" UNKNOWN FILE
SIZE</td></tr>\n";
$mark = 1;
} else {
if ($entry == ".") {
print "<tr><td><a
href=\"siteadmin.php?directory=\">$entry</a></td><td>directory</td></tr>\n";
} elseif ($entry == "..") {
print "<tr><td><a
href=\"siteadmin.php?directory=$old\">$entry</a></td><td>directory</td></tr>\n";
} else {
$direc = "$dir/$entry";
for ($i = 19; $i <= (strlen($direc) - 1); $i++) {
$direct = $direc{$i};
$dire = "$dire$direct";
}
for ($i = 19; $i <= (strlen($dir) - 1); $i++) {
$temp = $dir{$i};
$dirtemp = "$dirtemp$temp";
}
$old = $dirtemp;
print "<tr><td><a
href=\"siteadmin.php?directory=$dire&old=$old\">$entry</a></td><td>directory</td></tr>\n";
$dire = "";
}
}
}
print "</table><hr><br>\n";
if ($totaldirsize > 1023) {
$totaldirsize = $totaldirsize / 1024;
$mark++;
if ($totaldirsize > 1023) {
$totaldirsize = $totaldirsize / 1024;
$mark++;
if ($totaldirsize > 1023) {
$totaldirsize = $totaldirsize / 1024;
$mark++;
}
}
}
$totaldirsize = round($totaldirsize, 3);
if ($mark == 1)
print "<td>$totaldirsize Bytes</td></tr>\n";
elseif ($mark == 2)
print "$totaldirsize KBytes Total\n";
elseif ($mark == 3)
print "$totaldirsize MBytes Total\n";
elseif ($mark == 4)
print "$totaldirsize GBytes Total\n";
else
print "\"$totaldirsize\" \"$mark\" UNKNOWN TOTAL FILE SIZE\n";
$d->close();
?>
------------------------------------------------------------------------
[2003-03-02 12:25:43] msopacua@php.net
Yes, you said that already.
Let's see the script you used which exposes this bug.
For example - this works for me, using 4.3.1 on Windows 2k with
apache:
<?php
header('Content-Type: text/plain');
$dir = opendir('.');
while($entry = readdir($dir))
{
if(is_dir($entry))
echo "$entry is a dir\n";
else
echo "$entry is NOT a dir\n";
}
?>
------------------------------------------------------------------------
[2003-03-02 11:50:18] itamarc at rogers dot com
the is_dir is supposed to come back true if reading a directory and
false if not. it doesn't. it always comes back false.
if used as (not)!is_dir then it works right most of the time but still
give the wrong answer for some directories.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/22499
--
Edit this bug report at http://bugs.php.net/?id=22499&edit=1