Automation init...3
This commit is contained in:
parent
e392c9d19c
commit
a09a24221a
@ -46,9 +46,8 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
$this->makeDirectory($fullPath);
|
$this->makeDirectory($fullPath);
|
||||||
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $this->getOriginName();
|
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $this->getOriginName();
|
||||||
if (file_exists($saveFilePath)) {
|
if (file_exists($saveFilePath)) {
|
||||||
$fileInfos = pathinfo($saveFilePath, PATHINFO_ALL);
|
$saveFile = $this->getUniqueFilename($fullPath, $this->getOriginName());
|
||||||
$saveFile = base64_encode($fileInfos['filename']) . "." . $fileInfos['extension'];
|
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $saveFile;
|
||||||
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $this->getOriginName();
|
|
||||||
log_message("notice", __FUNCTION__ . "파일명 변경 : 원본파일 {$this->getOriginName()}->저장파일 {$saveFile}");
|
log_message("notice", __FUNCTION__ . "파일명 변경 : 원본파일 {$this->getOriginName()}->저장파일 {$saveFile}");
|
||||||
$this->setOriginName($saveFile);
|
$this->setOriginName($saveFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,4 +44,19 @@ trait FileTrait
|
|||||||
}
|
}
|
||||||
return $files;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user