Voici la version adaptée pour l'affichage dans un navigateur web, en utilisant des balises HTML pour le formatage :
function analyseEnvironnement($path) {
echo '<div style="font-family: monospace; white-space: pre-wrap;">';
echo "<h2>Informations système</h2>\n";
echo "Utilisateur : " . get_current_user() . "<br>\n";
echo "UID/GID : " . getmyuid() . "/" . getmygid() . "<br>\n";
echo "OS : " . PHP_OS . "<br>\n";
echo "PHP version : " . PHP_VERSION . "<br>\n";
echo "<h2>Liste des fichiers</h2>\n";
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST
);
// Style CSS pour la liste des fichiers
echo '<div style="background-color: #f5f5f5; padding: 10px; border-radius: 5px;">';
foreach ($iterator as $file) {
if ($file->isFile()) {
echo str_repeat(" ", $iterator->getDepth()) .
htmlspecialchars($file->getFilename()) .
" <span style='color: #666;'>(permissions: " .
substr(sprintf('%o', $file->getPerms()), -4) .
")</span><br>\n";
}
}
echo '</div></div>';
}
// Pour s'assurer que le contenu s'affiche correctement en HTML
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<title>Analyse de l'environnement</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #fff;
}
h2 {
color: #333;
border-bottom: 1px solid #ccc;
padding-bottom: 5px;
}
.file-list {
margin-left: 20px;
}
</style>
</head>
<body>
<?php
// Utilisation
analyseEnvironnement("/chemin/vers/dossier");
?>
</body>
</html>
Cette version :
- Utilise des balises HTML pour le formatage
- Ajoute des styles CSS pour une meilleure présentation
- Utilise
htmlspecialchars() pour sécuriser l'affichage des noms de fichiers
- Inclut une structure HTML complète
- Utilise des espaces insécables (
) pour l'indentation
- Ajoute de la couleur et du style pour une meilleure lisibilité
La sortie sera plus lisible dans le navigateur avec :
- Des retours à la ligne clairs
- Une hiérarchie visuelle des fichiers
- Un formatage cohérent
- Des couleurs pour distinguer les différents éléments
Vous pouvez ajuster les styles CSS selon vos préférences. Par exemple, pour un style plus moderne, vous pourriez ajouter :
function analyseEnvironnement($path) {
echo '<div class="container">';
echo '<div class="system-info">';
echo "<h2>Informations système</h2>";
echo '<table class="info-table">';
echo "<tr><td>Utilisateur :</td><td>" . get_current_user() . "</td></tr>";
echo "<tr><td>UID/GID :</td><td>" . getmyuid() . "/" . getmygid() . "</td></tr>";
echo "<tr><td>OS :</td><td>" . PHP_OS . "</td></tr>";
echo "<tr><td>PHP version :</td><td>" . PHP_VERSION . "</td></tr>";
echo "</table>";
echo "</div>";
echo '<div class="file-list">';
echo "<h2>Liste des fichiers</h2>";
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $file) {
if ($file->isFile()) {
echo '<div class="file-item" style="margin-left: ' . ($iterator->getDepth() * 20) . 'px">';
echo '<span class="file-name">' . htmlspecialchars($file->getFilename()) . '</span>';
echo '<span class="file-perms">(' . substr(sprintf('%o', $file->getPerms()), -4) . ')</span>';
echo "</div>\n";
}
}
echo "</div></div>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Analyse de l'environnement</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f0f2f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.system-info, .file-list {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h2 {
color: #1a73e8;
margin-top: 0;
}
.info-table td {
padding: 8px;
}
.file-item {
padding: 5px 0;
border-bottom: 1px solid #eee;
}
.file-name {
color: #333;
}
.file-perms {
color: #666;
margin-left: 10px;
font-size: 0.9em;
}
</style>
</head>
<body>
<?php analyseEnvironnement("/chemin/vers/dossier"); ?>
</body>
</html>