PHP Classes

File: explorer.php

Recommend this page to a friend!
  Classes of marcelo entraigas   Explorer   explorer.php   Download  
File: explorer.php
Role: Application script
Content type: text/plain
Description: landing page (use it as index.php)
Class: Explorer
Browse server side directories and files
Author: By
Last change: updated version.
Date: 15 years ago
Size: 6,604 bytes
 

Contents

Class file image Download
<?php
/** php Explorer is a directory browser. it is easy to use and have basic commands.
 * <br> It make use of css, so you can edit the styles to change the look.
 * <br>Tested on Firefox 2 and Opera 9.
 * <br>Last update: December 24, 2008.
 * <br>Author: Marcelo Entraigas <m_entraigas at yahoo dot com>.
 * <br>Licence: BSD License.
 */

session_start();
include(
'class.file_utils.php');

//where is my path?
if($_REQUEST['cmd']=='cd')
 
$fs = new file_utils($_REQUEST['val']);
elseif(isset(
$_SESSION['path']))
 
$fs = new file_utils($_SESSION['path']);
else
 
$fs = new file_utils();

//any other actions?
switch ($_REQUEST['cmd']) {
    case
'get':
       
$fs->download($_REQUEST['val']);
        break;
    case
'upload':
       
$fs->upload(_path);;
        break;
    case
'mkdir':
       
$fs->mkdir($_REQUEST['val']);
        break;
    case
'chmod':
      foreach (
$_REQUEST['files'] as $file) echo $fs->chmod(_path._slash.$file,$_REQUEST['val']);
        break;
    case
'rm':
      foreach (
$_REQUEST['files'] as $file) $fs->rm(_path.$file);
        break;
    default:
}

$fs->ls();

if (empty(
$fs->folders)){
   
$fs->folders['..'] = array('filepath'=>substr($_SESSION['path'],0,-1), 'description'=>htmlentities($_SESSION['path']));
}else{
   
$_SESSION['path'] = _path;
}

/*
//use post (javascript must be activated)
<a href="#" onclick="send('cd','<?php echo $attr['filepath']._slash;?>');">
<a href="#" title="Download!" onclick="send('get','<?php echo $attr['filepath'];?>');">

//or get?
<a href="?cmd=cd&val=<?php echo $attr['filepath']._slash;?>">
<a href="?cmd=get&val=<?php echo $attr['filepath'];?>" title="Download!">
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>php Explorer v2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
a:visited {color: #000000}
a:link {color: #000000}
a:hover {color: #0300FF}
body{
 font-family: Arial, Helvetica, sans-serif;
 font-size: 14px;
}
/* main table borders */
.bottom_table{
 font-family: Arial, Helvetica, sans-serif;
 border-left-style:solid;
 border-left-color:#FF8A00;
 border-left-width:3px;
 border-bottom-style:solid;
 border-bottom-color:#FF8A00;
 border-bottom-width:3px;
}
.top_table{
 font-family: Arial, Helvetica, sans-serif;
 border-right-style:solid;
 border-right-color:#FF8A00;
 border-right-width:3px;
 border-top-style:solid;
 border-top-color:#FF8A00;
 border-top-width:3px;
}
/* main table title */
.title{
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 14px;
 font-weight: bold;
 margin: 5px;
}
/* file table header (file, size, perms) */
.header{
 background-color: #FF8A00;
 color: white;
}
.row1{
 background-color: #FFFFFF;
}
.row0{
 background-color: #FFFFCC;
 border-top-width: 1px;
 border-top-style: solid;
 border-top-color: #FFFF99;
 border-bottom-width: 1px;
 border-bottom-style: solid;
 border-bottom-color: #FFFF99;
}
.button{
 font-family: Arial, Helvetica, sans-serif;
 background-color: #FFFFCC;
 border:solid;
 border-width: 1px;
 border-color:#660033;
 margin: 5px;
}
</style>
<script type="text/javascript">
function validate(){
 check = document.go.files;
  if(check.length){
    for(c=0; c<check.length; c++) {
      if(check[c].checked)
        return true;
    }
  } else {
    if(check.checked)
      return true;
  }
  alert('No files selected!');
  return false;
}
function check_all(value){
 check = document.go.files;
  if(check.length){
    for(c=0; c<check.length; c++)
      check[c].checked = value;
  } else check.checked = value;
}
function mkdir(){
  var pattern = new RegExp(/^[^\s]\w+/);
  dir = prompt('Directory name:');
  if(dir.length>0 && pattern.test(dir)){
    send('mkdir','<?php echo _path;?>' + dir);
  }
}
function chmod(){
  perm = prompt('Change permissions to:');
  if(perm.length>0 && validate()){
    send('chmod',perm);
  }
}
function rm(){
  if(validate() && confirm('Delete marked files?')){
    send('rm','');
  }
}
function send(cmd,val){
   document.forms.go.cmd.value = cmd;
   document.forms.go.val.value = val;
   document.forms.go.submit();
}
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="top_table">
<tr><td colspan="2" class="bottom_table"><div class="title"><?php echo _path;?></div></td></tr>
<tr valign="top">
 <td width="150" class="bottom_table" style="background-color: #FFFFCC;">
<?php foreach ($fs->folders as $folder => $attr):?>
<a href="?cmd=cd&val=<?php echo $attr['filepath']._slash;?>"><?php echo $folder;?></a><br>
<?php endforeach;?>
</td>
 <td width="90%" class="bottom_table">
  <form name="go" method="POST" action="<?php echo basename(__FILE__);?>">
   <input type="hidden" name="cmd" value="" >
   <input type="hidden" name="val" value="" >
<?php if(count($fs->files)):?>
<table border="0" width="100%" cellspacing="0" cellspacing="0">
    <tr class="header">
      <th>File</th><th>Size</th><th width="50">Perms</th><th width="130">Modified</th>
    </tr>
<?php foreach ($fs->files as $filename => $attr): $total+=$attr['size'];
     
$flag=!$flag;
     
$class=sprintf("row%b",$flag);?>
<tr align="left">
      <td class="<?php echo $class;?>"><input type="checkbox" id="files" name="files[]" value="<?php echo $filename;?>"><a href="#" title="Download!" onclick="send('get','<?php echo $attr['filepath'];?>');"><?php echo $filename;?></a></td>
      <td class="<?php echo $class;?>" align="center"><?php echo $fs->get_size($attr['size']);?></td>
      <td class="<?php echo $class;?>"><?php echo $attr['perms'];?></td>
      <td class="<?php echo $class;?>" align="center"><?php echo $attr['time'];?></td>
    </tr>
<?php endforeach;?>
<tr align="left" class="header"><th>Select all <input type="checkbox" onchange="if(this.checked)check_all(true); else check_all(false);"></th><th colspan="4" align="right"><?php echo count($fs->files)?> files - <?php echo $fs->get_size($total);?></th></tr>
   </table>
   <div align="center" style="width:70%; margin-top:15px;">
    <input type="button" value="chmod" onclick="chmod();" class="button">
    <input type="button" value="Delete" onclick="rm();" class="button">
    <input type="button" value="mkdir" onclick="mkdir();" class="button">
   </div>
<?php else:?>
<div class="header" style="padding-left:15px;"><b>No Files on this directory!</b></div>
<?php endif;?>
</form>
 </td>
</tr>
</table>
</body>
</html>