file management system (OOP Please)
Posted: Thu May 25, 2006 3:55 pm
I am looking for a decent (preferably object-oriented) file management system built with php that would be sorta modular and fairly easily brandable. Suggestions please!
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
What are you looking for in a file manager?The Ninja Space Goat wrote:I am looking for a decent (preferably object-oriented) file management system built with php that would be sorta modular and fairly easily brandable. Suggestions please!
Uploading "directories" is not really possible...I mean it is...but not using traditional FORM upload components...The Ninja Space Goat wrote:The most important feature it must have is multiple logins with different permissions (3 levels, admin - can do anything, user - can upload/download not delete, and visitor who can only download). It MUST be brandable. It needs to be able to upload/download/delete directories and files, and restrict file type and size. I think that is all.
The permissions is one system (part of your controllers), the file browser (and probably view/download/delete) is a separate thing, and upload is a third part. It should be pretty easy to build. The basics are easy ... it's all the fancy features (like Hockey's zip stuff) that gets detailed.The Ninja Space Goat wrote:The most important feature it must have is multiple logins with different permissions (3 levels, admin - can do anything, user - can upload/download not delete, and visitor who can only download). It MUST be brandable. It needs to be able to upload/download/delete directories and files, and restrict file type and size. I think that is all.
Code: Select all
<?php
class DirectoryBrowser {
var $param_dir = 'browse_dir';
var $param_area = 'browse_area';
var $basedir;
var $reldir = '';
var $entries = array();
var $dirs = array();
var $files = array();
var $entry_n = 0;
var $dir_n = 0;
var $file_n = 0;
var $entry_max = 0;
var $dir_max = 0;
var $file_max = 0;
function DirectoryBrowser ($basedir='') {
if ($basedir) {
$this->basedir = $basedir;
} else {
$this->basedir = $_SERVER['DOCUMENT_ROOT'];
}
if (substr($this->basedir, -1, 1) != '/') {
$this->basedir .= '/';
}
$this->reldir = preg_replace('/[^a-zA-Z0-9\-\_\.\/\ ]/', '', $_GET[$this->param_dir]);
$this->reldir = trim($this->reldir, '/');
if ($this->reldir != '') {
$this->reldir .= '/';
}
$this->relarea = preg_replace('/[^a-zA-Z0-9\-\_\.\/\ ]/', '', $_GET[$this->param_area]);
$this->relarea = trim($this->relarea, '/');
if ($this->relarea != '') {
$this->relarea .= '/';
}
}
function readDir () {
$directory = new DirectoryIterator($this->basedir . $this->relarea . $this->reldir);
$result = array();
$this->entry_n = 0;
$this->dir_n = 0;
$this->file_n = 0;
$this->entry_max = 0;
$this->dir_max = 0;
$this->file_max = 0;
$param = "{$this->param_area}={$this->relarea}&{$this->param_dir}=";
while ($directory->valid()) {
$filename = $directory->getFileName();
if ($directory->isDir()) {
if ($filename == '..') {
if ($this->reldir == '') {
$filename = '.'; // don't show
} else {
$pos = strrpos(trim($this->reldir, '/'), '/');
if ($pos === false) {
$dir = '';
} else {
$dir = substr($this->reldir, 0, $pos);
}
}
} else {
$dir = $this->reldir . $filename;
}
if ($filename != '.') {
$this->dirs[$this->dir_max++] = $this->entry_max;
$this->entries[$this->entry_max++] = array('type'=>'dir','param'=>"$param$dir", 'filename'=>$filename);
}
} else {
$this->files[$this->file_max++] = $this->entry_max;
$this->entries[$this->entry_max++] = array('type'=>'file','param'=>"$param{$this->reldir}", 'filename'=>$filename);
}
$directory->next();
}
return $this->entry_max;
}
function getBasePath() {
return $this->basedir;
}
function getPath() {
return $this->basedir . '/' . $this->reldir;
}
function getRelativePath() {
return $this->reldir;
}
function rewindFiles() {
$this->file_n = 0;
}
function nextFile() {
if ($this->file_n < $this->file_max) {
return $this->entries[$this->files[$this->file_n++]];
}
}
function rewindDirs() {
$this->dir_n = 0;
}
function nextDir() {
if ($this->dir_n < $this->dir_max) {
return $this->entries[$this->dirs[$this->dir_n++]];
}
}
}Code: Select all
<?php
include_once 'DirectoryBrowser.php';
$basedir = $_SERVER['DOCUMENT_ROOT'];
$browser = new DirectoryBrowser($basedir);
$browser->readDir();
$maxlength = 20;
$html = '';
while ($entry = $browser->nextDir()) {
if (strlen($entry['filename']) > $maxlength) {
$entry['filename'] = substr($entry['filename'], 0, $maxlength);
}
$html .= "<tr><td><a href=\"?{$entry['param']}\">{$entry['filename']}</a></td></tr>\n";
}
while ($entry = $browser->nextFile()) {
if (strlen($entry['filename']) > $maxlength) {
$entry['filename'] = substr($entry['filename'], 0, $maxlength);
}
$html .= "<tr><td>{$entry['filename']}</td></tr>\n";
}
?>
<doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>DirectoryBrowser Example</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
Browsing: /<?php echo $browser->getRelativePath(); ?><br/>
<div style="width: 300px; height: 200px; border: solid 1px gray; overflow: auto; ">
<table border="0" rowspacing="0" colspacing="0">
<?php echo $html ?>
</table>
</div>
</body>
</html>