How to make, what would the transition to folders, was using the GET method? I can not understand.

<?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 = __DIR__; $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>'; } elseif(is_dir($dir . '/' . $f)){ echo '<a href="?papka=' . $f . '">'; echo '<img src="' . $img . '">'; echo '<span style="display: inline-block; vertical-align: top; padding-left: 3px;">' . $f . '</span>'; echo '</a>'; } echo '</li>'; } echo '</ul>'; ?> 
  • And what you can not? - Anton Shchyrov
  • go to folders - DivMan

1 answer 1

Replace

$dir = __DIR__ ;

on

 $dir = __DIR__; if (isset($_GET['papka']) { $curDir = $_GET['papka']; $dir += $curDir; $curDir += '/' } else $curDir = ''; 

And here it is

echo '<a href="?papka=' . $f . '">';

Change to

 printf('<a href="%s?papka=%s%s">', $_SERVER['PHP_SELF'], $curDir, $f); 
  • And why is this not working? - DivMan
  • <! - language: lang-php -> <? php $ scan = DIR ; $ dir = scandir ($ scan); echo '<pre>'; print_r ($ dir); echo '</ pre>'; ?> <ol> <? foreach ($ dir as $ v):?> <? if (is_dir ($ scan. '/'. $ v)):?> <? php $ l = isset ($ link)? $ link. '/'. $ v: $ v; ?> <li id ​​= "dir"> <a href="fm.php?page=program&link=<?=$l?> "> <? = $ v?> </a> </ li> <? else :?> <li id ​​= 'file'> <? = $ v?> </ li> <? endif?> <? endforeach?> </ ol> - DivMan
  • @DivMan At least because you always scan the same directory $scan = __DIR__; $dir = scandir($scan) $scan = __DIR__; $dir = scandir($scan) - Anton Shchyrov
  • does not work> $ dir = DIR ; if (isset ($ _ GET ['papka'])) {$ curDir = $ _GET ['papka']; $ dir + = $ curDir; $ curDir + = '/'; } else {$ curDir = ''; } - DivMan
  • How do you insert php? why don't they write about it anywhere? And why admins will not add a button? - DivMan