Have PHP read the server folders [duplicate]

0

Colleagues.

I have now taken a project here at work, where back in the beginning this project was developed. It works as follows:

Some folders with jpg have been created on the page index.php, where it directs to the respective links. But files (PDF) are sent sent via FTP, where the industry here creates folders and subfolders and places these PDF files.

The person who made this "project" just changed the jpg image link on the home page. I thought about redoing this project, but there are already dozens of folders and subfolders with these pdf files.

When we click on the folder link, the index / of page and the file name appear:

What I thought of doing, creating a file in html or PHP, customizing and seeing if with PHP, JQuery, Ajax, I'm not sure, read the names of the folders / subfolders of the server and create something more personalized with image next to the file name or something along those lines.

    
asked by anonymous 17.01.2017 / 18:20

2 answers

4

In this way? In this case it selects the folder and returns the sub-folders in it. If it is, study a little about it. DirectoryIterator

<?php
    // atribuição a variável $dir
    $dir = new DirectoryIterator( './pasta/' );

    // atribui o valor de $dir para $file em loop
    foreach($dir as $file ) {
        // verifica se o valor de $file é diferente de '.' ou '..'
        // e é um diretório (isDir)
        if (!$file->isDot() && $file->isDir()) { 
            // atribuição a variável $dname
            $dname = $file->getFilename();

            // imprime o nome do diretório
            echo $dname."<br>";
        }
    }
?>
    
17.01.2017 / 18:28
-1

I tested this code here and served perfectly.

<?php

function listFolderFiles($dir)
{
    $ffs = scandir($dir);
    echo '<ol>';
    foreach ($ffs as $ff) {
        if ($ff != '.' && $ff != '..') {
            echo '<li>'.$ff;
            if (is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
            echo '</li>';
        }
    }
    echo '</ol>';
}
listFolderFiles('/websites/');
    
17.01.2017 / 18:27