Study/PHP [php] 메인접속시 가장 최근에 수정된 파일로 자동 접속하기 p0p0pret 2020. 12. 3. 17:10 index.php를 아래와 같이 설정해주면 된다. 디버깅 작업시 일일이 파일경로를 입력하지 않아도 되어 유용하다. 원출처: stackoverflow.com/questions/9371944/php-how-to-get-most-recent-file-from-directory-and-subdirectories PHP - how to get most recent file from directory AND subdirectories I have used the following script to correctly display ALL files from the selected directory and its sub-directories. Does anyone know how to modify this code only echo the most recent file across the stackoverflow.com <!DOCTYPE html> <html> <body> <script> <?php $mostRecentFilePath = ""; $mostRecentFileMTime = 0; $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("."), RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $fileinfo) { if ($fileinfo->isFile()) { if ($fileinfo->getMTime() > $mostRecentFileMTime) { if ($fileinfo->getPathname()=="./index.php") continue; //index 무한루프방지 $mostRecentFileMTime = $fileinfo->getMTime(); $mostRecentFilePath = $fileinfo->getPathname(); } } } ?> location.replace("<?=$mostRecentFilePath;?>") </script> </body> </html> 공유하기 게시글 관리 구독하기IT Center