절대경로
서버 내 최상위 디렉터리인 루트 (/, ROOT) 디렉터리부터 표기하는 경로.
예컨대 '/var/log/mail/' 혹은 윈도우즈에서 'C:\Users\Username\Documents'.
상대경로
현재 위치한 디렉터리를 기준으로 표기하는 경로. 현재 경로 표기는 '.', 상위 디렉터리는 '..'로 표기.
만약 '/var/log/mail/' 디렉토리와 '/var/home/' 디렉토리가 있다면 현재 '/mail/' 위치에서 '/home/'의 상대적 위치는 '../../home/'가 됩니다. 또한 '/log/' 위치에서 '/mail/'의 상대적 위치는 './mail/' 입니다.
PHP 예제코드
PHP 내장함수를 활용해 현재 코드가 입력되어 있는 파일의 절대경로와 상대경로를 다양한 방법으로 확인해 볼 수 있습니다.
// 현재 스크립트의 절대 경로
$currentPath = realpath(__DIR__);
// 상위 디렉토리의 절대 경로
$parentPath = realpath($currentPath . '/..');
// 다른 디렉토리의 절대 경로
$otherPath = realpath($currentPath . '/path/to/other/directory');
// 현재 스크립트와 다른 파일 간의 상대 경로
$relativePath = 'path/to/another/file.txt';
$relativeToCurrent = realpath($currentPath . '/' . $relativePath);
// 상위 디렉토리와 다른 파일 간의 상대 경로
$relativeToParent = realpath($parentPath . '/' . $relativePath);
// 출력
echo "Current Path: " . $currentPath . "\n";
echo "Parent Path: " . $parentPath . "\n";
echo "Other Path: " . $otherPath . "\n";
echo "Relative to Current: " . $relativeToCurrent . "\n";
echo "Relative to Parent: " . $relativeToParent . "\n";
참고
PHP: Hypertext Preprocessor
https://www.php.net
유용한 PHP 솔루션
https://www.ppcle.com/blog/php-scripts/
PHP GD 라이브러리, JPG PNG 손실 압축 비율
https://www.ppcle.com/blog/php-gd-library/