Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Verificam extensia
- function _is($file, $ext) {
- if (substr(strrchr(strtolower($file), '.'), 1) == $ext)
- return 1;
- else
- return 0;
- }
- // Functia principala
- function navigate_dir($dir) {
- // Daca directorul oferit e valid, atunci
- if ($handle = opendir($dir)) {
- // Afisam directorul curent
- echo 'Current Wording Directory: ' . getcwd() . '<br />';
- // Incepem generarea formularului si setam butonul "Go up"
- // Inputul hidden "prevdir" retine directorul curent si-l trimite prin POST
- // pentru a functiona cum trebuie butonul "Back"
- echo '<form action="" method="post">
- <input type="hidden" name="prevdir" value="' . getcwd() . '" />
- <input type="submit" name="gotodir" value="' . $dir . '/.." title="Go up" />';
- // Setam butonul "Back" doar dupa ce s-a accesat macar o data un alt director
- if (isset( $_POST['prevdir'])) {
- echo '
- <input type="hidden" name="prevdir" value="' . getcwd() . '" />
- <input type="submit" name="gotodir" value="' . $_POST['prevdir'] . '" title="Back" />';
- }
- // Afisam prima data directoarele
- while (false !== ($entry = readdir($handle))) {
- if ($entry != "." && $entry != "..") {
- if (is_dir($entry))
- echo '
- <input type="hidden" name="prevdir" value="' . getcwd() . '" />
- <br /><input type="submit" name="gotodir" value="' . $entry . '" />';
- }
- }
- // Inchidem formul pentru ca nu ne mai este de folos
- echo '</form>';
- closedir($handle);
- $handle = opendir($dir);
- // Afisam fisierele imediat dupa directoare
- while (false !== ($entry = readdir($handle))) {
- if ($entry != "." && $entry != "..") {
- if (! is_dir($entry))
- if (_is ($entry, 'txt') ||
- _is ($entry, 'png') ||
- _is ($entry, 'jpg') ||
- _is ($entry, 'jpeg') ||
- _is ($entry, 'zip') ||
- _is ($entry, 'tar') ||
- _is ($entry, 'gz') ||
- _is ($entry, 'css'))
- echo "<a href=\"./$dir/$entry\">$entry</a><br />";
- else
- echo "$entry<br />";
- }
- }
- // Inchidem directorul
- closedir($handle);
- }
- }
- if (isset($_POST['gotodir'])) {
- // Navigam pe directorul selectat daca s-a accesat unul
- navigate_dir($_POST['gotodir']);
- } else {
- // Daca nu este accesat niciun director inseamna ca s-a accesat
- // pagina pentru prima oara si deschidem directorul principal
- navigate_dir('.');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment