Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
Created June 3, 2015 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betweenbrain/e7c9ccc76df5ac8efe66 to your computer and use it in GitHub Desktop.
Save betweenbrain/e7c9ccc76df5ac8efe66 to your computer and use it in GitHub Desktop.
Get random image from Joomla directory
/**
* Returns a random image from /image/homeslides/
*
* @return mixed
*/
function randomImage()
{
// Use full system path for security
$files = glob(JPATH_BASE . '/images/homeslides/*.jpg');
// Get random image
$index = array_rand($files);
// Return path relative to base of site, not full system path
return str_replace(JPATH_BASE, JURI::base(true), $files[$index]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment