Introduce pet-projects dir
[lcapit-junk-code.git] / pet-projects / web / fsbrowser / fsbrowser.php
blob3ec38de08a226b2056283948ca9a072e2d98ae34
1 <html>
2 <head>
3 <link rel="stylesheet" type="text/css" href="fsbrowser.css"/>
4 </head>
5 <body>
6 <?php
7 $directory = ".";
9 function fsbrowser_init()
11 global $directory;
13 if (strlen($_GET["dir"]) > 0)
14 $directory = $_GET["dir"];
17 function remove_file()
19 $file = $_GET["remove"];
21 if ($file)
22 unlink($file);
25 function is_image($file)
27 $images = array("gif", "png", "jpg", "jpeg", "bmp", "svg");
29 foreach($images as $i)
30 if (strstr($file, "." . $i))
31 return true;
32 return false;
35 function is_php($fname)
37 if (strstr($fname, ".php"))
38 return true;
39 return false;
42 function put_icon($icon)
44 printf(" <td><img src=%s /></td>\n", $icon);
47 function put_tr()
49 static $light = 1;
51 if ($light == 1) {
52 $name = "light";
53 $light = 0;
54 } else {
55 $name = "dark";
56 $light = 1;
59 printf("<tr class='%s'>\n", $name);
62 function make_link($fname)
64 global $directory;
66 if ($fname == ".")
67 return;
69 put_tr();
71 $fpath = $directory . "/" . $fname;
72 if (is_dir($fpath)) {
73 put_icon("folder-icon.gif");
74 echo(" <td>");
75 echo("<a class='dir' href=fsbrowser.php?dir=" . $fpath . ">");
76 echo($fname . "</a></td>\n");
77 echo(" <td></td>\n");
78 } else {
79 if (is_image($fname))
80 put_icon("image-icon.gif");
81 else if (is_php($fname))
82 put_icon("php-icon.gif");
83 else
84 echo(" <td></td>\n");
85 echo(" <td>" . $fname . "</td>\n");
86 echo(" <td class='del'>");
87 printf("<a class='del' href=fsbrowser.php?dir=%s", $directory);
88 printf("&remove=%s>apagar</a>", $fpath);
91 echo("</tr>\n");
94 function list_dir()
96 global $directory;
98 printf("<h3>Caminho: %s/</h3>\n", $directory);
100 $files = scandir($directory);
101 if (!$files) {
102 echo("Diretorio vazio\n");
103 return;
106 echo("<table border='0'>\n");
108 foreach($files as $f)
109 make_link($f);
111 echo("</table>\n");
114 fsbrowser_init();
115 remove_file();
116 list_dir();
118 </body>
119 </html>