This code does not work:

$filelist = array(); if ($handle = opendir(".")) { while ($entry = readdir($handle)) { if (is_file($entry)) { $filelist[] = $entry; } } closedir($handle); } foreach ($filelist as $file) { printf("<td>%s</td><td class='action'><a href='#' class='view'>Загрузить</a><a href='#' class='delete'>Удалить</a></td>", $file); } 

Closed due to the fact that off-topic participants are Alexey Shimansky , aleksandr barakin , zRrr , Grundy , cheops 16 Apr '16 at 10:48 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - aleksandr barakin, zRrr, Grundy
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    I would strongly recommend first reading the manual , and then sculpt ...

    Here is an example from the manual:

     <?php // Обратите внимание, что оператор !== не существовал до версии 4.0.0-RC2 if ($handle = opendir('/path/to/files')) { echo "Дескриптор каталога: $handle\n"; echo "Файлы:\n"; /* Именно этот способ чтения элементов каталога является правильным. */ while (false !== ($file = readdir($handle))) { echo "$file\n"; } /* Этот способ НЕВЕРЕН. */ while ($file = readdir($handle)) { echo "$file\n"; } closedir($handle); } ?> 

    In your case, you can fix it on:

     <?php $filelist = array(); $dir = __DIR__; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (is_file($file)) $filelist[] = $file; } closedir($handle); } foreach ($filelist as $file) { printf("<td>%s</td><td class='action'><a href='#' class='view'>Загрузить</a><a href='#' class='delete'>Удалить</a></td>", $file); } ?>