PHP: DirectoryIterator - using http adrress and not an absolute path?

First of all, I create a site on a CD-ROM using Server2Go.

I am trying to use DirectoryIteratorto create a navigation bar taken directly from my folder / file structure of .php files. Here is my code:

<?php
$root = $_ENV["S2G_SERVER_DOCROOT"]."/content/";
$files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($root));
foreach($files as $file){
    echo '<li><a href=' . $file->getPathname() . '>' . $file->getPathname() . PHP_EOL . '</a></li>';
} 
?>

The problem is that it outputs the full absolute path for each folder / file (i.e. c: / etc. etc.), which causes the problem that the .php files do not open as they may only open with http based url. What I need is to output the paths as http: // paths or relative to the root of the website. There is another Server2Go ENV varialbe called S2G_BASE_URL which gives you your webroot hHttp: //127.0.0.1: 80 in this case), but I cannot use this with DirectortIterator, since it does not work with http addresses, it needs paths to the documents.

Does anyone have any thoughts on how I can do this?

+3
source share
1 answer

- getPathname, $_SERVER [ "DOCUMENT_ROOT" ] .

$ PATH = str_replace ($ _ SERVER [ "DOCUMENT_ROOT" ], '', $-> getPathname());

+2

Source: https://habr.com/ru/post/1779485/


All Articles