
SplFileInfo 클래스의 getPathname 메소드는 파일의 절대 경로를 반환합니다.
파일의 상대 경로를 반환하려면, getRelativePath 메소드를 사용하세요.
getRelativePath 메소드는 파일의 상대 경로를 반환합니다.
예를 들어, 다음 코드는 파일의 상대 경로를 반환합니다.
#hostingforum.kr
php
$filePath = '/var/www/html/file.txt';
$file = new SplFileInfo($filePath);
$relativePath = $file->getRelativePath();
echo $relativePath; // outputs: .
또는, 다음 코드는 현재 디렉토리의 상대 경로를 반환합니다.
#hostingforum.kr
php
$filePath = '/var/www/html/file.txt';
$file = new SplFileInfo($filePath);
$currentDir = dirname($filePath);
$relativePath = substr($filePath, strlen($currentDir) + 1);
echo $relativePath; // outputs: file.txt
2025-07-05 13:21