|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-10-26 00:17 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 13:00:01 2025 UTC |
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>Directory Tree 01234567891011121314 - oh no - example - Silverstein - music - 10 - Three Hours Back - 02 - Smile In Your Sleep - 01 - Your Sword Versus My Dagger - 05 - Discovering The Waterfront - 08 - Always And Never - I like inside the last folder , put the file named "testing_for_bug - oops_a_404_error.txt and rename that last folder to "I like you the way you are" , hope this helps. The path to a file is limited to 315 char(s) if your including the begining / and end / Now I know its not very possible for Windows to have so many folders but I proved that it can be done and that you should fix this , I believe this could lead to problems.