좋아, 마침내 php가 윈도우에서 심볼릭 링크를 처리 할 때이 버그를 해결할 수있는 해킹을 발견했다. 버그는 opendir()
을 사용하여 반복적으로 파일/디렉토리를 반복 할 때 발생합니다. 디렉토리에 대한 심볼릭 링크가 현재 디렉토리에 존재하면 opendir()
은 symlink 디렉토리의 디렉토리를 읽지 못합니다. 그것은 PHP의 statcache에서 펑키 한 것으로 인해 발생하며, 심볼릭 링크 인 opendir()
을 호출하기 전에 clearstatcache()
을 호출하여 해결할 수 있습니다 (또한 상위 디렉토리의 파일 핸들을 닫아야 함). 여기
는 수정의 예입니다
<?php
class Filesystem
{
public static function files($path, $stats = FALSE)
{
clearstatcache();
$ret = array();
$handle = opendir($path);
$files = array();
// Store files in directory, subdirectories can't be read until current handle is closed & statcache cleared.
while (FALSE !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..')
{
$files[] = $file;
}
}
// Handle _must_ be closed before statcache is cleared, cache from open handles won't be cleared!
closedir($handle);
foreach ($files as $file)
{
clearstatcache($path);
if (is_dir($path . '/' . $file))
{
$dir_files = self::files($path . '/' . $file);
foreach ($dir_files as $dir_file)
{
$ret[] = $file . '/' . $dir_file;
}
}
else if (is_file($path . '/' . $file))
{
$ret[] = $file;
}
}
return $ret;
}
}
var_dump(filessystem::files('c:\\some_path'));
편집 : 그것은 clearstatcache($path)
가 symlink'd 디렉토리의 모든 파일 처리 기능을하기 전에 호출해야 것으로 보인다. PHP가 symlink'd dir을 제대로 캐싱하지 않습니다.
탐색기에서 작동하지만 iis_user에보기 권한이 있습니까? –
@ 단 Thx! 하지만 아파치 (XAMPP 램프 스택)를 실행하고있어, PHP의 opendir() 버그가있는 것 같다. 5.3에서 수정되지 않은 2008 년 PHP 버그 보고서를 발견했습니다 : /. –