Skip to content

Instantly share code, notes, and snippets.

@tarangpanchal18
Last active May 1, 2023 10:51
Show Gist options
  • Select an option

  • Save tarangpanchal18/ba80437a39f547be57b60c8f14b729e5 to your computer and use it in GitHub Desktop.

Select an option

Save tarangpanchal18/ba80437a39f547be57b60c8f14b729e5 to your computer and use it in GitHub Desktop.
Common Useful functions for php
/**
* 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