Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dir = dirname(__FILE__);
- //--------------------------------------
- function srt($a, $b) {
- $a = $a['path'];
- $b = $b['path'];
- if (is_dir($a)) {
- if (is_dir($b)) {
- return strcasecmp($a,$b);
- }
- else return -1;
- } else {
- if (is_dir($b))
- return 1;
- else
- return strcasecmp($a,$b);}
- }
- //--------------------------------------
- function out($z) {
- $z1 = ($z['name']=='..') ? '..up' : $z['name'];
- echo "<li class=\"".(is_dir($z['path'])?'':'fl')."\"><a href=\"{$z['path']}\">$z1</a></li>";
- }
- //--------------------------------------
- function showdir($dirr) {
- $z = opendir($dirr);
- $files = array();
- while ($f= readdir($z)) {
- $el = array();
- $el['name'] = $f;
- $el['path'] = $dirr.'/'.$f;
- $files[] = $el;
- }
- closedir($z);
- usort($files, 'srt');
- array_splice($files,0, 1);
- array_walk($files,'out');
- }
- //--------------------------------------
- session_start();
- if (!isset($_SESSION['logged8'])) {
- if (isset($_POST['pass'])) {
- //$s = file_get_contents('hash.txt');
- $s = md5('pass');
- if (md5($_POST['pass'])==$s) {
- $_SESSION['logged8']=true;
- echo 'successfully logged in<br/>';
- echo '<a href="'.$_SERVER['PHP_SELF'].'" title="back" >back</a>';
- exit();
- } else {
- echo 'incorrect password<br/>';
- echo '<a href="'.$_SERVER['PHP_SELF'].'" title="back">back</a>';
- exit();
- }
- } else {
- $ss = <<<ZZ
- <form name="authform" action="{$_SERVER['PHP_SELF']}"
- method="post" enctype="application/x-www-form-urlencoded">
- <p>input password <input type="text" name="pass" /> </p>
- <input type="submit" value="send" />
- </form>
- ZZ;
- echo $ss;
- exit();
- }
- }
- if (isset($_GET['ajax'])) {
- switch ($_GET['action']) {
- case 'getfile' :
- $fn= $_GET['fname'];
- /*$fh = fopen ($fn, 'r');
- $i=1;
- $strz='';
- while ($row= fgets($fh)) {
- $row=htmlentities($row);
- $strz.= $row;
- $i++;
- }
- fclose($fh);*/
- $strz = htmlentities(file_get_contents($fn));
- $ctype='getfile';
- $content='<pre>'.$strz.'</pre>';
- $u = explode('/',$fn);
- $fn=array_pop($u);
- echo json_encode(Array('ctype'=>$ctype, 'content'=>base64_encode($content), 'fname'=>$fn));
- break;
- case 'getdir' :
- ob_start();
- showdir($_GET['fname']);
- $ctype = 'getdir';
- $content = ob_get_clean();
- echo json_encode(Array('ctype'=>$ctype, 'content'=>$content));
- break;
- }
- exit();
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title> file browser </title>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
- <script type="text/javascript">
- function decode_base64(s) {
- var e={},i,k,v=[],r='',w=String.fromCharCode;
- var n=[[65,91],[97,123],[48,58],[43,44],[47,48]];
- for(z in n){for(i=n[z][0];i<n[z][1];i++){v.push(w(i));}}
- for(i=0;i<64;i++){e[v[i]]=i;}
- for(i=0;i<s.length;i+=72){
- var b=0,c,x,l=0,o=s.substring(i,i+72);
- for(x=0;x<o.length;x++){
- c=e[o.charAt(x)];b=(b<<6)+c;l+=6;
- while(l>=8){r+=w((b>>>(l-=8))%256);}
- }
- }
- return r;
- }
- function onSuccess(inf,block) {
- if (inf.ctype=='getfile') {
- $('#messageload').html('');
- var tabs = $('#filebrowse ul');
- var l = tabs.children().length;
- tabs.prepend($('<li/>').data('inf',l).html(inf.fname).append($('<span/>').text('x')
- .click ( function(ev) {
- var liinf = $(this).parent().data('inf');
- $('#filebrowse div').filter(
- function(index) {
- return (liinf===$(this).data('inf'));
- }
- ).remove();
- var _selfp=$(this).parent().get(0);
- $(this).parent().parent().children().filter(
- function(index) {
- return (this!==_selfp)
- }
- )
- .first().trigger('click');
- $(this).parent().remove();
- }
- ))
- .click ( function(ev) {
- var liinf = $(this).data('inf');
- $('#filebrowse div[id!="messageload"]:visible').fadeOut('fast');
- $('#filebrowse div').filter(
- function(index) {
- return (liinf===$(this).data('inf'));
- }
- ).fadeIn('fast');
- }));
- $('#filebrowse').append($('<div/>').data('inf',l));
- $("#filebrowse div[id!='messageload']").fadeOut('fast');
- $('#filebrowse div:last').html(decode_base64(inf.content)).fadeIn('fast');
- }
- if (inf.ctype=='getdir') {
- $(block).html(inf.content);
- }
- init();
- busy=false;
- }
- function ajax_get(action, fname, block) {
- //if (window.busy)
- // return;
- busy=true;
- if (!block)
- block = $(document.body);
- switch (action) {
- case 'getfile':
- var zht = $('#messageload').html();
- $('#messageload').html(zht+fname+' loading, please wait...<br/>');
- break;
- case 'getdir':
- block.html('Loading...');
- break;
- }
- $.ajax({
- type: 'GET',
- url:"<?=$_SERVER["PHP_SELF"]?>",
- dataType: 'json',
- data: {
- ajax: '',
- action: action,
- fname: fname
- },
- success: function(inf) {
- onSuccess(inf, block);
- }
- })
- }
- $(document).ready(init);
- function init() {
- $('#dir_structure li.fl').children('a').unbind('click').click (
- function(ev) {
- var fname = $(this).attr('href');
- ajax_get('getfile', fname);
- return false;
- } );
- $('#dir_structure li:not(.fl)').children('a').unbind('click').click(
- function(ev) {
- var el = $('<ul/>');
- $(this).parent().append(el);
- var fname = $(this).attr('href');
- ajax_get('getdir', fname, el);
- return false;
- }
- );
- $("#dir_structure li a:contains('..up')").unbind('click').click (
- function(ev) {
- var el = $('#dir_structure');
- var fname = $(this).attr('href');
- ajax_get('getdir', fname, el);
- return false;
- }
- );
- $("#dir_structure li ul li a:contains('..up'), a:contains('close..')")
- .html('close..')
- .unbind('click').click (
- function(ev) {
- var _el = $(this);
- $.when ($(this).parent().parent().slideUp('slow')).done(
- function() {
- _el.parent().parent().remove();
- }
- );
- return false;
- }
- );
- }
- </script>
- <style type="text/css">
- * {
- margin:0;
- padding:0;
- }
- body {
- font-family: verdana, sans-serif;
- font-size: 1.2em;
- }
- li {
- list-style-type: none;
- }
- a {
- text-decoration: none;
- color: #400;
- }
- a:hover {
- text-decoration: underline;
- }
- #dir_structure {
- padding: 10px;
- border: solid 1px #eee;
- background-color: #ffe;
- margin:50px 0 0 20px;
- float:left;
- width:300px;
- }
- #dir_structure li ul {
- margin-left: 10px;
- margin-bottom: 20px;
- }
- .fl a{
- color: #900;
- }
- #filebrowse {
- margin:50px 0 0 350px;
- background-color: #fffff0;
- font-family: "courier new", monospace;
- font-size: 12px;
- padding: 5px;
- border: solid 1px #aaa;
- word-wrap:break-word;
- }
- #filebrowse ul {
- margin-bottom:10px;
- float:left;
- width: 100%;
- }
- #filebrowse ul li {
- float: left;
- cursor:pointer;
- margin: 0 5px 5px 0;
- border: solid 1px #888;
- border-radius: 7px;
- padding: 4px 8px;
- }
- #filebrowse ul li:hover {
- background: #666;
- color: white;
- }
- #filebrowse ul li span {
- padding-left:10px;
- padding-right:10px;
- }
- #filebrowse ul li span:hover {
- color: red;
- }
- #filebrowse div {
- display: none;
- }
- #filebrowse #messageload {
- display: block;
- }
- </style>
- </head>
- <body>
- <ul id="dir_structure">
- <?php
- showdir($dir);
- ?>
- </ul>
- <div id="filebrowse">
- <div id="messageload"></div>
- <ul></ul>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment