
ZipArchive::statName 메소드는 압축 파일 내의 파일 이름을 포함한 전체 경로를 반환합니다. 예를 들어, 압축 파일 내의 파일 이름이 "example.txt"인 경우, ZipArchive::statName을 사용하여 가져온 결과는 "/example.txt"입니다.
파일 이름만 가져오고 싶다면, explode() 함수를 사용하여 경로를 분리하고, 파일 이름만 가져올 수 있습니다. 예를 들어,
#hostingforum.kr
php
$filePath = ZipArchive::statName($zipFile, $fileName);
$fileName = basename($filePath);
파일 이름이 다중으로 존재하는 경우를 대비하여, 파일 이름이 중복되는 것을 방지하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$files = $zip->getArchiveName();
foreach ($files as $file) {
if (strpos($file, $targetFileName) !== false) {
echo $file . "n";
}
}
압축 파일 내의 파일 이름을 가져올 때, 파일 이름이 특정 패턴에 맞는 경우를 필터링하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$files = $zip->getArchiveName();
foreach ($files as $file) {
if (preg_match('/^example.w+$/i', $file)) {
echo $file . "n";
}
}
파일 이름이 특정 문자열을 포함하는 경우를 필터링하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$files = $zip->getArchiveName();
foreach ($files as $file) {
if (strpos($file, 'string') !== false) {
echo $file . "n";
}
}
위의 예제는 PHP의 ZipArchive 클래스를 사용하여 압축 파일 내의 파일 이름을 가져올 때, 파일 이름이 특정 패턴에 맞는 경우를 필터링하는 방법을 보여줍니다.
2025-03-18 19:16