Last active
May 1, 2023 10:51
-
-
Save tarangpanchal18/ba80437a39f547be57b60c8f14b729e5 to your computer and use it in GitHub Desktop.
Common Useful functions for php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Function to generate File Name | |
| * | |
| * @param string $extension | |
| * @param string $prefix | |
| * @return string | |
| */ | |
| function generateRandomName($extension = '', $prefix = '') { | |
| $bytes = random_bytes(16); | |
| $name = bin2hex($bytes); | |
| if (! empty($prefix)) { | |
| $name = $prefix . '-' . $name; | |
| } | |
| if (! empty($extension)) { | |
| $name .= '.' . $extension; | |
| } | |
| return $name; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment