Skip to content

Commit

Permalink
Merge pull request #13 from UserKazun/ui
Browse files Browse the repository at this point in the history
create filename method
  • Loading branch information
u2d-man authored Mar 12, 2023
2 parents 568684e + ea96cc8 commit c3c88e0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/Services/UploadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ public function moveUploadedFile(string $directory, Request $request): string
$getFile = $request->getUploadedFiles();
$file = $getFile['files'];
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
$basename = bin2hex(random_bytes(8));
$filename = sprintf('%s.%0.8s', $basename, $extension);
$filename = $this->createUniqueFilename($extension);

$file->moveTo($directory . DIRECTORY_SEPARATOR . $filename);

return $filename;
}

private function createUniqueFilename(string $extension): string
{
$basename = bin2hex(random_bytes(8));

return sprintf('%s.%0.8s', $basename, $extension);
}
}

0 comments on commit c3c88e0

Please sign in to comment.