How to make navigation?

So that this script creates a new page after 20 outputs and so on until the end of the files. Specifically needed for WordPress. Why do I need it? The page is too large. Or maybe there are other options, flash drive, flame - which is not very desirable.

$dir = opendir("/files/"); //путь к файлам while ($file = readdir($dir)) { if (($file != ".") && ($file != "..") && ($file != "index.php")) { $cat = "$file"; // строка, подлежащая частичной замене $r = array( "yo", "ye", "ts", "ch", "sh", "shch", "yu", "ya", "a", "b", "v", "g", "d", "e", "j", "z", "i", "y", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "e", "_", "h" ); // что менять ("a" и "b"); $r2 = array( "ё", "ё", "ц", "ч", "ш", "щ", "ю", "я", "а", "б", "в", "г", "д", "е", "г", "з", "и", "и", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "Э", " ", "х" ); // на что менять ("0" и "1"); $trans = str_ireplace($r, $r2, $cat); echo '<img src="/themes/present/images/PostCategoryIcon.png" WIDTH="50" HEIGHT="50" alt=""><a href="/files/' . $file . '">' .$trans. '</a><br>'; } } closedir($dir); 
  • Do you need a paginator? The phrase "to the end of the files" confuses me. - Cooleronline
  • The script displays links to files in a folder, say 1000 or 5000, it turns out a very large page. It is necessary to break 5000 files into pages of 20 files on one. - Gitaros
  • paginator - hmm already have something to think about ... - Gitaros
  • I think this topic name is more understandable to the participants of the Cham Navigation for php program ... - Palmervan

2 answers 2

Generally lazy ... Paginated output files from the folder

ZY And carefully read the last post, it was written for you!

     <?php if ($handle = opendir('./files')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $files[] = $file; } } closedir($handle); } /* config */ $COUNT_FILES_ON_PAGE = 7; ### $COUNT_FIELES = count($files); $COUNT_PAGES = intval($COUNT_FIELES / $COUNT_FILES_ON_PAGE); if(empty($_GET['p']) || $_GET['p'] < 0 || $_GET['p'] > $COUNT_PAGES || !intval($_GET['p'])) $_GET['p'] = 0; echo '<h2>Файлов в папке: '.$COUNT_FIELES.'</h2>'; echo 'Всего страниц: <b>'.($COUNT_PAGES +1).'</b><br>'; echo 'Файлов на страницу: <b>'.$COUNT_FILES_ON_PAGE.'</b><br>';; echo 'Текущая страница: <b>'.($_GET['p']+1).'</b><br>'; echo '<center>Если закачка не началась вставте ссылку в свой менеджер закачек (Download Master)</center><br>'; for ($i=0; $i<= $COUNT_PAGES;$i++) { echo '<a href="?p='.$i.'">['.($i+1).']</a> '; } echo '<hr>'; $START = $_GET['p'] * $COUNT_FILES_ON_PAGE; $END = $START + $COUNT_FILES_ON_PAGE; for ($i = $START; $i < $END; $i++) { if(key_exists($i,$files)) { if(is_file('./files/'.$files[$i])) $cat = "$files[$i]"; //строка, подлежащая частичной замене $r=array("yo","ye","ts","ch","sh","shch","yu","ya","a","b","v","g","d","e","j","z","i","y","k","l","m","n","o","p","r","s","t","u","f","e","_","h","w"); // ??????"a" ?b"); $r2=array("ё","ё","ц","ч","ш","щ","ю","я","а","б","в","г","д","е","г","з","и","и","к","л","м","н","о","п","р","с","т","у","ф","э"," ","х","в"); // ???????"0" ?1"); $trans = str_ireplace($r,$r2,$cat); echo ' <img src="/gitara/themes/present/images/PostCategoryIcon.png" WIDTH="50" HEIGHT="50" alt=""><a href="/gitara/files/'.$file.'" title="'.$trans.' скачать ноты, табы">Табы: '.$trans.'</a><br>'; if(is_dir('./files/'.$files[$i])) echo $files[$i].' - [DIR]<br>'; } } ?>