Automation init...3

This commit is contained in:
최준흠 2024-09-14 20:52:27 +09:00
parent e392c9d19c
commit a09a24221a
2 changed files with 17 additions and 3 deletions

View File

@ -46,9 +46,8 @@ class FileLibrary extends MyStorageLibrary
$this->makeDirectory($fullPath);
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $this->getOriginName();
if (file_exists($saveFilePath)) {
$fileInfos = pathinfo($saveFilePath, PATHINFO_ALL);
$saveFile = base64_encode($fileInfos['filename']) . "." . $fileInfos['extension'];
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $this->getOriginName();
$saveFile = $this->getUniqueFilename($fullPath, $this->getOriginName());
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $saveFile;
log_message("notice", __FUNCTION__ . "파일명 변경 : 원본파일 {$this->getOriginName()}->저장파일 {$saveFile}");
$this->setOriginName($saveFile);
}

View File

@ -44,4 +44,19 @@ trait FileTrait
}
return $files;
}
final public function getUniqueFilename($path, $file_name)
{
$fileExtension = pathinfo($file_name, PATHINFO_EXTENSION);
$fileBaseName = pathinfo($file_name, PATHINFO_FILENAME);
$newFilename = $file_name;
$counter = 1;
// 중복된 파일명이 존재하는지 확인
while (file_exists($path . DIRECTORY_SEPARATOR . $newFilename)) {
// 중복된 파일명이 존재하면 숫자를 추가하여 새로운 파일명 생성
$newFilename = $fileBaseName . '_' . $counter . '.' . $fileExtension;
$counter++;
}
return $newFilename;
}
}