ID:               34983
 User updated by:  trustpunk at hotmail dot com
 Reported By:      trustpunk at hotmail dot com
 Status:           Open
 Bug Type:         Directory function related
 Operating System: Windows XP
 PHP Version:      5.0.5
 New Comment:

The opendir had a small bug in it. Its Fixed!

<pre>
<?php
$dir = "dir... here";
$open = opendir($dir);

while($file = readdir($open)) {

 $file_name = "$dir/" . $file;

 if (is_file($file_name)) {
  echo $file . " Size: " . 
  filesize($file_name) . "<br>";
 }

}
closedir($open);
?> 
</pre>


Previous Comments:
------------------------------------------------------------------------

[2005-10-26 00:17:45] trustpunk at hotmail dot com

Description:
------------
When you use a path thats greater than 246 char(s) and the file within
that path is greater than 22 char(s). A Warning Will be shown using the
following code below. This is a bug!

Now I know its a bit overkill to have a path so big but when your
creating a directory listing script , you want to be able to list all
files no matter how big the path to the files are.

Note: Im not using Symbolic Links. Im only using a relative
path within the current directory the script is in.



Reproduce code:
---------------
Using the opendir() method to list files.

<?php
$dir = opendir("dir... here");

while($file = readdir($dir)) {

 $file_name = "$dir/" . $file;

 if (is_file($file_name)) {
  echo $file_name . " Size: " . 
  filesize($file_name) . "<br>";
 }
}
closedir($dir);
?> 

Using the glob() method to list files.

<?php
$dir = "dir... here";

foreach(glob("$dir/*.mp3") as $file_name) {
 echo $file_name . " Size: " . 
 filesize($file_name) . "<br>";
}
?>

Using glob(); function to list files will just report
a Warning that the foreach loop failed and what not. 

Expected result:
----------------
I expect all files to be listed without Warnings!

Actual result:
--------------
I get a bunch of Warnings when using the opendir() method and a Warning
when I use the glob() function to list the files.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=34983&edit=1

Reply via email to