I'm trying to display the folder icon next to the folder, but it turns out that the icon is first displayed, and then everything else, I do not understand how to do it correctly.

My result

<?php error_reporting(-1); header('Content-Type: text/html; char set=utf-8'); ini_set('display_errors', 'On'); //$dir = $_SERVER['DOCUMENT_ROOT'] . '/tmp'; $images = array('papka.jpg'); $dir = 'C:\OpenServer\domains\localhost\kurs\16\dzfm'; $files1 = scandir($dir); ?> <?php if(is_dir($_SERVER['DOCUMENT_ROOT'])){ foreach ($images as $img){ } ?> <img src="<?php echo $img; ?>"> <?php print_r($files1)?> <?php } ?> 
  • The picture probably should be placed inside the loop? Although, what's the difference, she is there alone. - vp_arth
  • "I'm trying to display the folder icon next to the folder, but it turns out that the icon is first displayed" - some kind of nonsense. - n.osennij
  • foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $filename => $fileInfo){} - user207618

1 answer 1

 $img = 'papka.jpg'; $dir = 'C:\OpenServer\domains\localhost\kurs\16\dzfm'; $files = scandir($dir); foreach ($files as $f) { if (is_dir(dir . '/' . $f)) { echo '<img src="' . $img . '">'; } echo $f, ' '; } 

Naturally, the conclusion must be more cultural.