Why is the path for the folder not inserted into the link, and how to display the image of the folder, only for the folder?

Now I have images of the folder for all files except text and images.

Is it even possible to somehow check for a folder?

<?php error_reporting(-1); header('Content-Type: text/html; char set=utf-8'); ini_set('display_errors', 'On'); $img = 'papka.jpg'; $img2 = 'file.jpg'; $img3 = 'img.jpg'; $dir = 'C:\OpenServer\domains\localhost\kurs\16\dzfm'; $dir2 = 'localhost\kurs\16\dzfm'; $files = scandir($dir); echo '<ul style="padding: 0">'; foreach ($files as $f) { echo '<li style="list-style: none;">'; if(pathinfo($f, PATHINFO_EXTENSION) == 'txt'){ echo '<img src="' . $img2 . '">'; echo "<span style=' display: inline-block; vertical-align: top; padding-left: 3px;'>$f</span>"; } elseif(pathinfo($f, PATHINFO_EXTENSION) == 'jpg'){ echo '<img src="' . $img3 . '">'; echo "<span style=' display: inline-block; vertical-align: top; padding-left: 3px;'>$f</span>"; } else{ echo ""?><a href="<?php '"' . $dir2 . '\\' . $f . '"'?>"><?php echo ""; echo '<img src="' . $img . '">'; echo "<span style=' display: inline-block; vertical-align: top; padding-left: 3px;'>$f</span>"; echo '</a>'; } echo '</li>'; } echo '</ul>'; echo $dir2 . '\\' . $f; ?> <a href=<?php '"' . $dir2 . '\\' . $f . '"'?>>ссылка<a/> 

I replaced the else with such a check and for some reason also outputs everything, and not just the folders

 elseif(!is_file($dir2 . '\\' . $f)){ 

this also does not work elseif

 (is_dir($dir2 . '\\' . $f)){ 
  • You for some reason display text mixed with PHP in else - why? Print the link to else without ""?> Or <? Php echo - now you are trying to output lines FOR a PHP file from a PHP file. Output as in the previous conditions, without it. - Daniel Protopopov
  • Have you ever tried to first prepare an array of data and then output it? and not all in a pile folded? - teran
  • First, work with the data without their output - create an array. And only then output them as it should. There will be no this porridge. Everything will be neat and beautiful. And do not get confused. Try it. Then update the question with new code. No one is that now will not dig. - n.osennij

0