|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-14 11:47 UTC] BinaryKitten at jkrswebsolutions dot co dot uk
Description:
------------
When using the DirectoryIterator to go through files/folders on Windows under apache, the path has a mismatch of \ and /
Reproduce code:
---------------
<?php
$dir = new DirectoryIterator( $_SERVER['DOCUMENT_ROOT'] );
echo "<strong>".$dir->getPath()."</strong><br />";
foreach($dir as $file ) {
$dirName = $file->getPathname();
echo $dirName."<br />";
}
?>
Expected result:
----------------
With the Document root as C:\HTDOCS Apache returns $_SERVER['DOCUMENT_ROOT'] as c:/HTDOCS
Expected Output
C:/HTDOCS/.
C:/HTDOCS/..
C:/HTDOCS/css
C:/HTDOCS/index.php
C:/HTDOCS/js
C:/HTDOCS/
Actual result:
--------------
C:/HTDOCS\.
C:/HTDOCS\..
C:/HTDOCS\css
C:/HTDOCS\index.php
C:/HTDOCS\js
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 09:00:01 2025 UTC |
FilesystemIterator is not available in the 5.2.9 codebase, 5.3+ so FilesystemIterator doesn't resolve the issue. What does is passing the $_SERVER['DOCUMENT_ROOT'] to realpath before passing the result to the DirectoryIterator; <?php $dir = new DirectoryIterator( realpath($_SERVER['DOCUMENT_ROOT']) ); echo "<strong>".$dir->getPath()."</strong><br />"; foreach($dir as $file ) { $dirName = $file->getPathname(); echo $dirName."<br />"; } ?> This "solves" the issue.