라이브러리

[PHP] SplFileInfo::getFilename - 파일 이름을 가져옵니다.




SplFileInfo는 PHP의 SPL(Split) 모듈에서 제공하는 클래스입니다. 이 클래스는 파일 정보를 나타내는 객체를 생성할 수 있게 해줍니다. SplFileInfo::getFilename 메소드는 파일 이름을 반환하는 메소드입니다.

SplFileInfo::getFilename 메소드


SplFileInfo::getFilename 메소드는 파일 이름을 반환합니다. 이 메소드는 파일 경로에서 파일 이름을 분리하여 파일 이름만 반환합니다.

예제


#hostingforum.kr
php

// 파일 경로를 지정합니다.

$file_path = '/var/www/html/test.txt';



// SplFileInfo 객체를 생성합니다.

$file_info = new SplFileInfo($file_path);



// 파일 이름을 얻습니다.

$filename = $file_info->getFilename();



// 결과를 출력합니다.

echo "파일 이름: $filename";



결과


#hostingforum.kr


파일 이름: test.txt



SplFileInfo::getFilename 메소드 사용 예제


#hostingforum.kr
php

// 파일 경로를 지정합니다.

$file_path = '/var/www/html/test.txt';



// SplFileInfo 객체를 생성합니다.

$file_info = new SplFileInfo($file_path);



// 파일 이름을 얻습니다.

$filename = $file_info->getFilename();



// 파일 확장자를 얻습니다.

$file_extension = $file_info->getExtension();



// 결과를 출력합니다.

echo "파일 이름: $filename";

echo "파일 확장자: $file_extension";



결과


#hostingforum.kr


파일 이름: test.txt

파일 확장자: txt



SplFileInfo::getFilename 메소드 사용 예제 (폴더 경로)


#hostingforum.kr
php

// 폴더 경로를 지정합니다.

$folder_path = '/var/www/html';



// SplFileInfo 객체를 생성합니다.

$folder_info = new SplFileInfo($folder_path);



// 폴더 이름을 얻습니다.

$folder_name = $folder_info->getFilename();



// 결과를 출력합니다.

echo "폴더 이름: $folder_name";



결과


#hostingforum.kr


폴더 이름: html



SplFileInfo::getFilename 메소드 사용 예제 (파일 경로와 폴더 경로)


#hostingforum.kr
php

// 파일 경로를 지정합니다.

$file_path = '/var/www/html/test.txt';



// 폴더 경로를 지정합니다.

$folder_path = '/var/www/html';



// SplFileInfo 객체를 생성합니다.

$file_info = new SplFileInfo($file_path);

$folder_info = new SplFileInfo($folder_path);



// 파일 이름을 얻습니다.

$filename = $file_info->getFilename();



// 폴더 이름을 얻습니다.

$folder_name = $folder_info->getFilename();



// 결과를 출력합니다.

echo "파일 이름: $filename";

echo "폴더 이름: $folder_name";



결과


#hostingforum.kr


파일 이름: test.txt

폴더 이름: html



SplFileInfo::getFilename 메소드 사용 예제 (파일 이름과 확장자)


#hostingforum.kr
php

// 파일 경로를 지정합니다.

$file_path = '/var/www/html/test.txt';



// SplFileInfo 객체를 생성합니다.

$file_info = new SplFileInfo($file_path);



// 파일 이름을 얻습니다.

$filename = $file_info->getFilename();



// 파일 확장자를 얻습니다.

$file_extension = $file_info->getExtension();



// 결과를 출력합니다.

echo "파일 이름: $filename";

echo "파일 확장자: $file_extension";



결과


#hostingforum.kr


파일 이름: test.txt

파일 확장자: txt



SplFileInfo::getFilename 메소드 사용 예제 (폴더 이름과 경로)


#hostingforum.kr
php

// 폴더 경로를 지정합니다.

$folder_path = '/var/www/html';



// SplFileInfo 객체를 생성합니다.

$folder_info = new SplFileInfo($folder_path);



// 폴더 이름을 얻습니다.

$folder_name = $folder_info->getFilename();



// 폴더 경로를 얻습니다.

$folder_path = $folder_info->getPath();



// 결과를 출력합니다.

echo "폴더 이름: $folder_name";

echo "폴더 경로: $folder_path";



결과


#hostingforum.kr


폴더 이름: html

폴더 경로: /var/www


  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 145 페이지

검색

게시물 검색