The output files from the folder?

Hi!
Recently asked me how to get the list of files for the slider, but the topic is stalled.
How list the files in a folder?

there is a code tag
spoiler
<?php
 $fienames = glob('/img/*.png');
 foreach ($filenames as $filename) {
 echo "<div-->$filename
"; } ?>
5a36ad8adc1f0184533746.pngThe files themselves
But it glows white in the editor and does not work including the hosting.
In the folder only 5 images.
How to fix errors in this code?
Thanks for the replies!
June 10th 19 at 14:22
2 answers
June 10th 19 at 14:24
Solution
Ochepyatka is the worst enemy of the encoder:
$fienames !== $filenames

After correcting two ochepyatka:
5a36b5eb88ec3972355710.jpeg
Oh, how much is nerves are lost because of a simple comma =) - Lisette commented on June 10th 19 at 14:27
even the closing tag of the PHP looked like this:
/?> - Baylee_Kulas commented on June 10th 19 at 14:30
June 10th 19 at 14:26
Solution
<?php
 $dir = 'images/'; 
 $cols = 3; 
 $files = scandir($dir); 
 echo "<table-->";
 $k = 0; 
 for ($i = 0; $i < count($files); $i++) { 
 if (($files[$i] != ".") && ($files[$i] != "..")) { 
 if ($k % $cols == 0) echo ""; 
 echo ""; 
 $path = $dir.$files[$i]; 
 echo "<a href="$path">"; 
 echo "<img src="$path" alt width="100">"; 
 echo "</a>"; 
 echo ""; 


 if ((($k + 1) % $cols == 0) || (($i + 1) == count($files))) echo "";
$k++;
}
}
 echo ""; 
?>

tested it personally
Thank you!
But as a picture not a table issue and inside div ?
List type
the <div>img.png</div>
the <div>img.png</div>
the <div>img.png</div>
 the <div>img.png</div>
- Lisette commented on June 10th 19 at 14:29
you can't get there div and insert the same img is also not necessary ...
just write echo and how your code is written - Baylee_Kulas commented on June 10th 19 at 14:32
I've just got a slider is. his slides are laid out divами. I was wondering how to make the formation of these DIVS from the folder. that is to say to minimize the content of slider without code. - Lisette commented on June 10th 19 at 14:35
have reduced the code to this:
<?php
 $dir = 'img/'; 
 $cols = 3; 
 $files = scandir($dir); 
 $k = 0; 
 for ($i = 0; $i < count($files); $i++) { 
 if (($files[$i] != ".") && ($files[$i] != "..")) { 
 echo "<div-->"; 
 $path = $dir.$files[$i]; 
 echo "<a href="$path">"; 
 echo "<img src="$path" alt width="100">"; 
 echo "</a>"; 
 echo ""; 
}
}
?>


Thank you!
It works!! - Caesar.Keeli commented on June 10th 19 at 14:38
I left - I'm glad that helped - Lisette commented on June 10th 19 at 14:41

Find more questions by tags PHP