Created
June 3, 2015 19:41
-
-
Save betweenbrain/e7c9ccc76df5ac8efe66 to your computer and use it in GitHub Desktop.
Get random image from Joomla directory
This file contains 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
/** | |
* 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