I have a directory containing the sub-directory, in each sub-directory there are images. I want to display the images randomly. Below my code in php that works well, but it does not work in Laravel, problem with opendir and readdir.
view blade
<?php
$folder = opendir('images/');
$i = 0;
while(false !=($file = readdir($folder))){
if($file != "." && $file != ".."){
$images[$i]= $file;
$i++;
}
}
$random_img=rand(0,count($images)-1);
?>
<div>
<?php
echo '<img src="images/'.$images[$random_img].'" alt="" />';
?>
</div>
Aucun commentaire:
Enregistrer un commentaire