Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function uniqueFilename(array $file) : string {
- if(is_array($file) and $file['name'] !== '') {
- $extension = pathinfo($file['name'], PATHINFO_EXTENSION);
- $file_name = uniqid() . '.' . $extension;
- if(file_exists('/path/to/file' . $file_name)) {
- static::uniqueFileName($file);
- return '';
- }
- return $file_name;
- } else {
- throw new \Exception("Invalid file.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement