라이브러리
[PHP] SplFileInfo::setFileClass - SplFileInfo::openFile과 함께 사용되는 클래스를 설정합니다.
SplFileInfo::setFileClass
PHP의 `SplFileInfo` 클래스는 파일 정보를 나타내는 클래스입니다. 이 클래스는 파일의 이름, 경로, 크기, 권한, 타입, 마지막 수정 시간, 마지막 접근 시간, 마지막 변경 시간, 등과 같은 정보를 제공합니다.
`SplFileInfo::setFileClass` 메서드는 파일 정보를 나타내는 클래스를 설정하는 메서드입니다. 이 메서드는 `SplFileInfo` 객체의 파일 정보를 나타내는 클래스를 설정하도록 합니다.
예제
#hostingforum.kr
php
// SplFileInfo 객체 생성
$file = new SplFileInfo('example.txt');
// 현재 파일 정보를 나타내는 클래스 확인
echo $file->getClass() . "
"; // SplFileInfo
// 새로운 클래스를 설정
$file->setFileClass('MyFileInfo');
// 새로운 클래스를 확인
echo $file->getClass() . "
"; // MyFileInfo
MyFileInfo 클래스
#hostingforum.kr
php
class MyFileInfo extends SplFileInfo {
public function __construct($filename) {
parent::__construct($filename);
}
public function getFilename() {
return $this->getFilename();
}
public function getMimeType() {
return $this->getMimeType();
}
public function getTimestamp() {
return $this->getTimestamp();
}
}
MyFileInfo 클래스를 사용하는 예제
#hostingforum.kr
php
// MyFileInfo 객체 생성
$file = new MyFileInfo('example.txt');
// 파일 이름 확인
echo $file->getFilename() . "
"; // example.txt
// MIME 타입 확인
echo $file->getMimeType() . "
"; // text/plain
// 타임스탬프 확인
echo $file->getTimestamp() . "
"; // 파일의 마지막 수정 시간
결론
`SplFileInfo::setFileClass` 메서드는 파일 정보를 나타내는 클래스를 설정하는 메서드입니다. 이 메서드는 `SplFileInfo` 객체의 파일 정보를 나타내는 클래스를 설정하도록 합니다. 예제를 통해 `MyFileInfo` 클래스를 사용하여 파일 정보를 나타내는 클래스를 설정하는 방법을 보여드리겠습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.