Edit report at https://bugs.php.net/bug.php?id=48547&edit=1

 ID:                 48547
 Comment by:         vitoandre dot doria at gmail dot com
 Reported by:        BinaryKitten at jkrswebsolutions dot co dot uk
 Summary:            DirectoryIterator Slash issue with getPathname
                     Windows with Apache
 Status:             Not a bug
 Type:               Bug
 Package:            SPL related
 Operating System:   win32 only - WinXP SP3
 PHP Version:        5.2.9
 Assigned To:        garretts
 Block user comment: N
 Private report:     N

 New Comment:

I really disagree with garretts "Not a bug" statement.

First of all if you had read the PHP Target Version you would know there is no 
FilesystemIterator in 5.2 Branch.

Secondly if the directoryIterator uses "the default platform slash" like you 
indicate then PHP or better the DirectoryIterator should:

A: treat the Path "c:/some/path/" as unresolvable as you state it doesnt use 
this slashes!
B: more likely convert all forward slashes on the target version to the 
"default 
platform slash" (you are doing this anyway for the 
last slash as you indicate which is clearly inconsistent)

Also have a note on: http://msdn.microsoft.com/en-
us/library/windows/desktop/aa365247(v=vs.85).aspx
It clearly states that the API would swap "ALL" forward slashes with backward 
slashes and not only the last one! Like 
directoryIterator does


BinaryKitten stated realpath would fix this issue which doesnt always apply as 
it might return null for the current path while 
DirectoryIterator returns a path (see: 
http://php.net/manual/en/function.realpath.php) which means this problem relys 
unresolved!

The "Not a bug" philosophy here on bugs.php.net in the last years is getting 
ill 
imho!


Previous Comments:
------------------------------------------------------------------------
[2009-09-06 14:57:00] BinaryKitten at jkrswebsolutions dot co dot uk

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.

------------------------------------------------------------------------
[2009-08-19 18:02:22] garre...@php.net

Use the FilesystemIterator class (a subclass of DirectorIterator) if you want 
to force the directory separator to the forward slash.

Directory iterator only supports the default platform slash.

http://us.php.net/manual/en/class.filesystemiterator.php

// will use forward slashes.
$dir = new FilesystemIterator( $path, 8192 );





------------------------------------------------------------------------
[2009-06-14 19:22:59] webmaster at asylum-et dot cm

I have tested this on Windows XP SP3 with PHP 5.2.5 and have the same 
findings as BinaryKitten at jkrswebsolutions dot co dot uk

------------------------------------------------------------------------
[2009-06-14 11:47:49] 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



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



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

Reply via email to