Displays a list of files with thumbnails in the directory?

Good day!
Please help!
<?php
header("Content-Type: text/html; charset=utf-8");
$sPath = '.';
$dDir = opendir($sPath); // open the directory $dDir descriptor 
while ( false !== ($sFileName=readdir($dDir)) )

{
 if ($sFileName!='.' && $sFileName!='..' && $sFileName!='alldoc.php' && $sFileName!='meddoc.php')
{
 echo ('<table-->'.$sFileName.'<a href="'.$sFileName.'">Download</a>');
}
}
closedir ($dDir);


?>


Please tell me how to do to 1) correctly show file names in Russian(now gibberish) and next to the icons, display file icons( the icons I will prepare).
Please tell me how to do to output, not all files, and let the first 10, and then there was the transition to another page. pagination.
Kindly asking for help. Thank you.
June 27th 19 at 15:33
1 answer
June 27th 19 at 15:35
Solution
Something like this:
header("Content-Type: text/html; charset=utf-8");
$sPath = '.';
$dDir = opendir($sPath); // open the directory $dDir descriptor 
$ignore_list = ['.', '..', 'alldoc.php', 'meddoc.php'];
while ( false !== ($sFileName = readdir($dDir)) ) {
 if (! in_array($sFileName, $ignore_list)) {
 $info = pathinfo($sFileName);
 $ext = $info['extension'];
 echo ('<table><tbody><tr><td>'
 . '<img src="/papcastle/'. $ext .'.png">'
 . $sFileName.'</td><td><a href="'.$sFileName.'">Download</a></td></tr></tbody></table>');
}
}
closedir ($dDir);


php.net/manual/en/function.pathinfo.php

And on account of the gibberish - something wrong with encoding. Generally it depends on the environment settings, but if laziness to understand can nakostylyat using iconv.
: with version 5.4 available a short way of writing arrays. If you have an older version replace
$ignore_list = array('.', '..', 'alldoc.php', 'meddoc.php');
- Austen.Thompson53 commented on June 27th 19 at 15:38
Please tell me, now it turns out that just inserted the picture. .png
and how to make for each file type were substituted a picture of? (icon), png, pdf, xml , doc etc - nikita.Stracke commented on June 27th 19 at 15:41
: no, now populated not just .png and given the file extension.

/papcastle/doc.png
/papcastle/txt.png
/papcastle/pdf.png - Austen.Thompson53 commented on June 27th 19 at 15:44
: Thank you very much! IT WORKS! great solution! THANK you!
ALL THE BEST!!! - nikita.Stracke commented on June 27th 19 at 15:47

Find more questions by tags PHP