bit dojo labs : file explorer
Viewing contents of file:
home
/
php
/
file-explorer
/file-explorer.php
<?php // // Bit Dojo File Explorer // http://bitdojo.net/file_explorer // // Copyright (C) 2008 Alan Huan-Chun Peng Hsu (http://bitdojo.net) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // //== Configuration ============================================================== $site_name = "bit dojo labs : file explorer"; $ignores = array(".", ".."); $script_root = "http://labs.bitdojo.net"; $browse_cmd = "/browse/"; // "/?open="; $view_cmd = "/view/"; // "/?open="; //== End of Configuration ======================================================= $version = "v0.5 (20080822)"; $browse_cmd = $script_root.$browse_cmd; $view_cmd = $script_root.$view_cmd; $mydir = getcwd(); $qtype = $_REQUEST["type"]; $open = $_REQUEST["open"]; if(!$open) $open = "."; ?> <html> <head> <title><?php echo $site_name?></title> <style type="text/css"> body { margin: 0px; padding: 10px; font: 18px Calibri; color: #888; background: #fff; } h1, h2, h3 { margin: 0px 0px; } a { color: #555; text-decoration: none; } a:hover { color: #000; cursor: pointer; text-decoration: underline; } div { width: 90%; padding: 5px; margin: 20px 0px; background: #555; text-align: justify; } table { width: 60%; border: none; border-spacing: 0px; border-collapse: collapse; } tr:hover td, tr.highlight td { background: #efe; } td { padding: 5px 10px; margin: 0px 0px; } .filename { width: 60%; } .fileinfo { width: 20%; font-size: 12px; margin: 0px 0px; text-align: center; } .footer { font-size: 12px; width: 90%; padding: 0px 0; margin: 0px 0px; background: transparent; } textarea { width: 99%; height: 90%; } </style> <script src="/js/lib/codepress/codepress.js" type="text/javascript"></script> </head> <body id="body"> <?php // Security Check $ohno = strstr($open, "..") || (!strstr(realpath($open), $mydir)); if($ohno) exit("It is pitch black. You are likely to be eaten by a grue."); ?> <h2 id="title1"><?php echo $site_name?></h2> <?php if(is_dir($open)){ // if this is a dir $numfiles = 0; $numdirs = 0; chdir($open); if ($handle = opendir(".")) { $cwd = getcwd(); $cwd = str_replace($mydir, "", $cwd); $cwd = trim($cwd, "/"); //$cwd = ($cwd == "") ? "(root)" : $cwd; $breadcrumb = BuildBreadcrumb($cwd); echo "Browsing directory: $breadcrumb<br />"; $files = array(); $dirs = array(); while (false !== ($file = readdir($handle))) { if (!in_array($file, $ignores)){ if(!is_dir("$file")) $files[] = $file; else $dirs[] = $file; } } sort($files); sort($dirs); $files = array_merge($dirs, $files); closedir($handle); if($files){ echo "<table id='FileTable'>"; foreach ($files as $file) { $filepath = "$open/$file"; $filepath = str_replace("./", "", $filepath); echo "<tr>"; if(is_dir("$file")){ echo "<td class='filename'>[ <a href='$browse_cmd$filepath'>$file</a> ]</td>"; echo "<td class='fileinfo'></td>"; echo "<td class='fileinfo'> folder </td>"; $numdirs+=1; } else { $size = filesize("$file"); echo "<td class='filename'><a target='_blank' href='/$filepath'>$file</a></td> "; echo "<td class='fileinfo'> <a href='$view_cmd$filepath'>view contents</a></td>"; echo "<td class='fileinfo'> $size bytes </td>" ; $numfiles+=1; } echo "</tr>"; } echo "<table>"; ?> <script type="text/javascript"> // Fix for IE not supporting tr:hover var rows = document.getElementById('FileTable').rows; for(i=0;i<rows.length;i++){ rows[i].onmouseover = RowHover; rows[i].onmouseout = RowNormal; } function RowHover(){ this.className = "highlight"; } function RowNormal(){ this.className = ""; } </script> <?php } } echo "<b>$numfiles file".(($numfiles==1)?"":"s"); echo " and $numdirs folder".(($numdirs==1)?"":"s")."</b>"; } else { // else this is a file $type = ($qtype) ? $qtype : FindFileType($open); $p = BuildBreadcrumb($open); echo "Viewing contents of file: $p <br />"; echo "<textarea id='txtfld1' wrap='off' class='codepress $type'>"; echo htmlentities(file_get_contents($open)); echo "</textarea><br/>"; echo "<span class='footer'>"; echo "Current syntax highlight: <b>$type</b>. "; //.((!$qtype)?(" (auto)"):("")).". "; echo "Select a different type: "; echo "<a href='$view_cmd$open&type=csharp'>csharp</a> | "; echo "<a href='$view_cmd$open&type=css'>css</a> | "; echo "<a href='$view_cmd$open&type=generic'>generic</a> | "; echo "<a href='$view_cmd$open&type=html'>html</a> | "; echo "<a href='$view_cmd$open&type=java'>java</a> | "; echo "<a href='$view_cmd$open&type=javascript'>javascript</a> | "; echo "<a href='$view_cmd$open&type=perl'>perl</a> | "; echo "<a href='$view_cmd$open&type=ruby'>ruby</a> | "; echo "<a href='$view_cmd$open&type=text'>text</a> | "; echo "<a href='$view_cmd$open&type=sql'>sql</a> | "; echo "<a href='$view_cmd$open&type=vbscript'>vbscript</a><br/>"; echo "</span>"; } ?> <div class="footer"> Bit Dojo File Explorer <?php echo $version; ?> Copyright © 2008 </div> </body> </html> <?php // Functions function BuildBreadcrumb($path){ global $browse_cmd, $script_root; $breadcrumb = ""; if($path == ""){ $breadcrumb = "home"; } else { $a = explode("/", $path); foreach($a as $v){ $breadcrumb = $breadcrumb.($breadcrumb==""?"":"/").$v; $paths[] = $breadcrumb; } $breadcrumb = "<a href='$script_root'>home</a>"; for($i=0;$i<count($a);$i++){ if($i!=count($a)-1) $breadcrumb = $breadcrumb."/"."<a href='$browse_cmd$paths[$i]'>$a[$i]</a>"; else $breadcrumb = $breadcrumb."/".$a[$i]; } } return $breadcrumb; } function FindFileType($path){ //$types["ext"] = "type"; $types["generic"] = "generic"; $types["cs"] = "csharp"; $types["css"] = "css"; $types["html"] = "html"; $types["htm"] = "html"; $types["java"] = "java"; $types["js"] = "javascript"; $types["pl"] = "perl"; $types["rb"] = "ruby"; $types["php"] = "php"; $types["txt"] = "text"; $types["sql"] = "sql"; $types["vbs"] = "vbscript"; $path = strtolower($path) ; $ext = split("[/\\.]", $path) ; $n = count($ext)-1; $ext = $ext[$n]; $ext = $types[$ext]; if(!$ext)$ext = "generic"; return $ext; } ?>
Current syntax highlight:
php
. Select a different type:
csharp
|
css
|
generic
|
html
|
java
|
javascript
|
perl
|
ruby
|
text
|
sql
|
vbscript