|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34983 glob/opendir (path limit)
Submitted: 2005-10-26 00:17 UTC Modified: 2005-10-27 15:37 UTC
From: trustpunk at hotmail dot com Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5.0.5 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: trustpunk at hotmail dot com
New email:
PHP Version: OS:


 [2005-10-26 00:17 UTC] trustpunk at hotmail dot com
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.

$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>";

Using the glob() method to list files.

$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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-26 00:38 UTC] trustpunk at hotmail dot com
The opendir had a small bug in it. Its Fixed!

$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>";

 [2005-10-26 03:55 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed already according to user.
 [2005-10-26 20:04 UTC] trustpunk at hotmail dot com
Im sorry to say but PHP - v5.0.6 Dev did not fix it. Here's
the path I was using , you can see if from the PHP error.

Warning: filesize() [function.filesize]: stat failed for 6c7695d7af/ohn/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 you the way you are/01 - Your Sword Versus My Dagger.mp3 in C:\Website\directory_listing.php on line 82
 [2005-10-26 21:30 UTC]
So, what should one do to reproduce it?
What should be the directory structure etc. ?
 [2005-10-26 21:38 UTC] trustpunk at hotmail dot com
Directory Tree

- 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.
 [2005-10-27 06:19 UTC] trustpunk at hotmail dot com
I found the real problem!

Lets say I choose a download directory "dir"

When I put a 255 char(s) file/dir inside the "dir" folder
 , I want to be able to see it listed from PHP , is there
a way you guy's can fix this problem im having ?

Note: Apache has no problems with letting me download a
file so it can't be the 255 char(s) limit in Windows. :-)

Also , im only using Apache to test this. I use (Abyss)!
 [2005-10-27 15:37 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

This bug is a duplicate of an existing bug #31347
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 09:01:27 2024 UTC