PHP Classes

File: abrowser.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of George Clarke  >  ABrowser Class  >  abrowser.php  >  Download  
File: abrowser.php
Role: Application script
Content type: text/plain
Description: Application to maintain filesystem of webserver
Class: ABrowser Class
Browse server side files and folders
Author: By
Last change: Mostly comments about the added download feature.
Date: 9 years ago
Size: 11,740 bytes


Class file image Download
// This is an application for maintaining the file system of a web server.
// It will display the file system from it's resident folder and down.
// It will not move up in the folder tree from it's resident folder.
//  (That is so a user can have his own folder and won't access others.)
// It's features are:
//  list folders (The folders are listed in the first column)
//  list files (The files are listed in the next three columns: images, scripts and .txt files)
//   (the images listed can either be a list of filenames, or displayed as thumbnails)
//   (click on the image name or thumbnail to show the full size image)
//  edit a file's contents and save it with the same name or different file name,
//   in same folder or another one
//  display listing of a file
//  delete a file
//  delete an empty folder
//  while editing a file, find a text string
//  navigate back up the tree using unique navigation links
//  create a new file and then enter text into it
//  create a new folder
//  upload a file into the currently displayed folder
//  download a file to your computer
// This application uses the php class of Olaf Lederer, Easy PHP Upload class, which can be found here:
// The upload_class.php file is really all you need for this application
// This application uses the php class of Slava Ivanov, Downloadfileclass, which can be found here:
// The file is really all you need for this application

// Version 1.0.1   27Feb2006
// Corrected a number of errors in the code. Too many to list.
// Version 1.0.2   28Feb2006
// corrected a couple of other errors that were missed.
// Version 1.0.3   04Oct2006
// Added a download feature for each file or image to the class.
//   Version 1.0.2 should still work with the updated class.
//   Changes to this application were comments.


<script language="JavaScript">
// This JavaScript code performs the "Find" function in the "Edit" screen.
var TRange=null;
var TRange0=null;
var strFound=false;

function findString (str) {
 if (parseInt(navigator.appVersion)<4) return;
 if (navigator.appName=="Netscape") {


  if (!strFound) {
   while (fedit.txt.find(str,0,1)) continue
 if (navigator.appName.indexOf("Microsoft")!=-1) {


  if (TRange!=null) {
   if (strFound);
  if (TRange==null){
   if (strFound){;
 if (!strFound) alert ("String '"+str+"' not found!");

function srange(){
 TRange.moveToPoint(window.event.x, window.event.y);


// The next two lines can be commented out after fully testing
//   the abrowser application in it's own folder on your server.

require 'class.abrowser.php';

// Login Code. This is very simple for a single user/password.
// You should change this to whatever login system you are using.
// The initial username is "username" and password is "password"

// ########## Be sure to change it for your own ##############
  if("username"==$user && md5("password")==$pw){

  print "Sorry, wrong login.";
// Check for logged in user
// If not logged in, display form for user/password
 print "<html><head></head><body>";
 print "<form method='post' action='".$_SERVER['PHP_SELF']."'><br>";
 print "Username: <input type='text' name='user' size=30><br>";
 print "Password: <input type='password' name='pw' size=30><br>";
 print "<input type='submit' name='login' value='Login'><br>";
 print "</form>";
 print "</body></html>";
// End of login code
// If logged in, proceed
 (isset($_GET['sp'])) ? $spath=$_GET['sp'] : $spath="./";
 (isset($_GET['sub'])) ? $sub=$_GET['sub']."/" : $sub="";
 (isset($_GET['pic'])) ? $pic=$_GET['pic'] : $pic="";
 (isset($_GET['lst'])) ? $list=$_GET['lst'] : $list="";
 (isset($_GET['edit'])) ? $edit=$_GET['edit'] : $edit="";
 $dr = new abrowser();
 $rt=$_SERVER['HTTP_HOST'] . str_replace("\\","/",dirname($_SERVER['PHP_SELF']));
 $dr->setPath($spath, $sub);
//  This is used for the navigation links at the top of each screen
 $roots = "http://" . $_SERVER['HTTP_HOST'] . str_replace("\\","/",dirname($_SERVER['PHP_SELF']));
 if(!(substr($roots,strlen($roots)-1,1) == "/")){
 $rel = str_replace($rt,"",$dr->getPath());
// Save an edited file
  $r= realpath(dirname($dr->getRoot())).$sep;
  print $fpth." was saved successfully.<br>";

// Delete a file
 if(isset($_POST['delete']) && $_POST['cdel']=='on'){
  print "$fpth was deleted successfully.<br>";

// Delete an empty folder
 if(isset($_POST['ddelete']) && $_POST['cdel']=='on'){
   print "Deleted folder $rp<br>\n";

// Upload a file to the server
// This uses the php class of Olaf Lederer, Easy PHP Upload class, which can be found here:
// The upload_class.php file is really all you need for this application
  $my_upload = new file_upload;
// these are file types to allow to be uploaded
  $my_upload->extensions = array(".html",".htm",".php",".asp",".xml",".inc",".js",".xsl",".css",".txt",".gif",".jpg",".png",".ttf"); // specify the allowed extensions here
  $my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100) 
  $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
  $my_upload->the_file = $_FILES['upload']['name'];
  $my_upload->http_error = $_FILES['upload']['error'];
  $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
  $my_upload->do_filename_check = "y"; // use this boolean to check for a valid filename
  print "<br>".$my_upload->show_error_string()."<br>";

// Create a new file or new folder
// Create a new file (document)
   print "create $edit";
// Create a new folder
   print "<br>create folder $sub<br>";
   $rel = str_replace($rt,"",$dr->getPath());
// Get the directory list of folders
 print "<html><head></head><body>\n";
 print realpath($dr->getPath()).$sep;

// Show navigation links at the top

 if($pic=="" && $list=="" && $edit==""){
// Display the forms above the folder and file lists
  print "<FORM METHOD='POST' ACTION='".$_SERVER['PHP_SELF']."?sp=" . $dr->getPath()."'>";

// if the current displayed folder is empty, show the delete folder button
   print "<FONT TITLE='Check OK and click [DELETE] to delete this folder from the web server.\n";
   print " (Cannot be undone.)' FACE='Arial, Helvetica, sans-serif' SIZE=1>\n";
   print "<B>OK TO DELETE THIS EMPTY FOLDER? (Cannot be undone!)</B></FONT>\n";
   print "<input type='checkbox' name='cdel'>\n";
   print "<input type='submit' name='ddelete' value='Delete'><br>\n";

// Show the create new folder/file form
  print "Create New  <INPUT TYPE='RADIO' NAME='type' VALUE='doc' CHECKED>DOCUMENT -OR- ";
  print "<INPUT TYPE='RADIO' NAME='type' VALUE='fold'>FOLDER:   NAME ";
  print "<INPUT TYPE='TEXT' NAME='new' SIZE=14>";
  print "<INPUT TYPE='SUBMIT' name='create' VALUE='CREATE'>";
  print "</FORM>";

// Show the file upload form
  print "<form name='form1' enctype='multipart/form-data' method='POST' action='".$_SERVER['PHP_SELF']."?sp=" . $dr->getPath()."'>";
  print "<input type='hidden' name='MAX_FILE_SIZE' value='$max_size'>";
  print "Upload File <input type='file' name='upload' size='30'>";
  print "Replace ? <input type='checkbox' name='replace' value='y'>";
  print "<input type='submit' name='fupload' value='Upload'>";
  print "</form><br>";
 print "<table border='1' width='100%'>\n";
 print "<tr valign='top'><td valign='top'>\n";
//  Show the directories in this column
 print "Directories<br>";
 print "<br>\n";

// Edit a file
  print "<td valign='top' bgcolor='#99ccff'>\n";
  print "</td>";

// Display a single image or photo
  print "<td valign='top' bgcolor='#99ccff'>\n";
  print "<a href='".$_SERVER['PHP_SELF']."?sp=$spath' align='left'>Go Back</a><br>\n";
  print "</td>";

// Display a listing of a file
  print "<td valign='top' bgcolor='#99ccff'>\n";
  print "</td>";

// Display the files in three columns
 if($pic=="" && $list=="" && $edit==""){
  print "</td><td bgcolor='#99ccff'>\n";

//  Show the images in this column
  print "Images&nbsp;&nbsp;&nbsp;";
// If "thumbs" is set, display the images as thumbnails
   print "<a href='".$_SERVER['PHP_SELF']."?sp=$spath&thmb=yes' align='right'>Show Thumbs</a><br><br>\n";
// If not set, list the filenames
   print "<a href='".$_SERVER['PHP_SELF']."?sp=$spath&thmb=no'>Show List</a><br><br>\n";
  print "</td><td bgcolor='#99ccff'>\n";

//  Show every file but these types in this column
  print "Scripts<br>";
  print "</td><td bgcolor='#99ccff'>\n";

//  Show the .txt files in this column
  print "Text Files<br>";

 print "</td></tr></table>\n";
 print "</body></html>";
// And that is all