라이브러리
[PHP] filemtime - 파일 수정 시간을 가져옵니다
PHP의 filemtime 함수
PHP의 `filemtime` 함수는 특정 파일의 마지막 수정 시간을 반환하는 함수입니다. 이 함수는 파일의 수정 시간을 초 단위로 반환하며, Unix 시간으로 표현됩니다.
# 사용법
`filemtime` 함수는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
filemtime($filename)
* `$filename` : 파일의 경로를 지정합니다.
# 예제
#hostingforum.kr
php
// 파일의 경로를 지정합니다.
$filename = 'example.txt';
// filemtime 함수를 사용하여 파일의 마지막 수정 시간을 가져옵니다.
$lastModified = filemtime($filename);
// Unix 시간을 초 단위로 변환하여 년, 월, 일, 시간, 분, 초를 출력합니다.
echo "파일의 마지막 수정 시간: " . date('Y-m-d H:i:s', $lastModified);
# 예제 결과
파일 `example.txt`가 생성된 후에, `example.txt`를 수정한 후에 다음과 같은 결과가 출력됩니다.
#hostingforum.kr
파일의 마지막 수정 시간: 2024-02-17 14:30:00
# 예제 2 - 파일의 마지막 수정 시간을 비교하기
#hostingforum.kr
php
// 파일의 경로를 지정합니다.
$filename1 = 'example1.txt';
$filename2 = 'example2.txt';
// filemtime 함수를 사용하여 파일의 마지막 수정 시간을 가져옵니다.
$lastModified1 = filemtime($filename1);
$lastModified2 = filemtime($filename2);
// 두 파일의 마지막 수정 시간을 비교합니다.
if ($lastModified1 > $lastModified2) {
echo "example1.txt가 example2.txt보다 최근에 수정되었습니다.";
} elseif ($lastModified1 < $lastModified2) {
echo "example2.txt가 example1.txt보다 최근에 수정되었습니다.";
} else {
echo "두 파일의 마지막 수정 시간은 같습니다.";
}
# 예제 결과
파일 `example1.txt`와 `example2.txt`가 생성된 후에, `example1.txt`를 수정한 후에 다음과 같은 결과가 출력됩니다.
#hostingforum.kr
example1.txt가 example2.txt보다 최근에 수정되었습니다.
# 참고
* `filemtime` 함수는 파일이 존재하지 않으면 `false`를 반환합니다.
* `filemtime` 함수는 파일의 마지막 수정 시간을 초 단위로 반환하며, Unix 시간으로 표현됩니다.
댓글목록
등록된 댓글이 없습니다.