Make PHP read server folders

Asked

Viewed 756 times

0

Colleagues.

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

It was created in the index.php page some folders with jpg, where it directs to the respective links. But the (PDF) files are sent via FTP, where the sector here of work creates folders and subfolders and places these PDF files.

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

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

inserir a descrição da imagem aqui

What I thought to do, create a file in html or PHP, customize and see if with PHP, Jquery, Ajax, I don’t know for sure, read in the names of the folders/ subfolders of the server and create something more customized with image next to the name of the file or something in this sense.

  • What have you tried to do? What is your question?

  • 3

    "are sent faggots via FTP" - kkkkk

  • I think he wants to list all the PDF’s that are in the respective folders dynamically, without having to add the link manually in the file index. From what I noticed, there will be a problem, the images in the current list is manually associated to the PDF (not inside the same as the respective PDF), or is? Only he can answer.

  • 1

    Filipe, exactly that. One opens the FTP, creates the folders and plays the PDF inside. In many cases, it also creates subfolders.

  • Hello William. The PHP file will be inside the server, but outside the folders and subfolders, in the root folder.

  • 1

    @Fox.11 is this http://answall.com/q/108662/3635?

Show 1 more comment

2 answers

4


This way? In this case it selects the folder and returns the existing subfolders in it. If it is, study a little about. 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>";
        }
    }
?>
  • 2

    +1 I didn’t know that one. Thanks, @Pedroquezado!!!

  • 3

    Seriously, it would be really good for the community and interesting for everyone if they could really mark the question as dup, instead of generating repetitive responses to something that has been asked dozens of times, it would bring a huge benefit to the whole community: http://answall.com/search?q=%5Bphp%5D+List+files

-1

I tested that code from 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/');
  • 4

    Seriously, it would be really good for the community and interesting for everyone if they could really mark the question as dup, instead of generating repetitive responses to something that has been asked dozens of times, it would bring a huge benefit to the whole community: http://answall.com/search?q=%5Bphp%5D+List+files

  • 1

    Let’s do this

Browser other questions tagged

You are not signed in. Login or sign up in order to post.