php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: trustpunk at hotmail dot com
New email:
PHP Version: OS:

 

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

Patches

Pull Requests

History

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!

<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>
 [2005-10-26 03:55 UTC] iliaa@php.net
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
http://snaps.php.net/.
 
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] tony2001@php.net
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


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.
 [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] iliaa@php.net
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: Sat Dec 21 14:01:32 2024 UTC