.
*
*/
/**
* Class for fileserver access
*
*/
class OC_FILES {
/**
* show a web GUI filebrowser
*
* @param basedir $basedir
* @param dir $dir
*/
public static function showbrowser($basedir,$dir){/*
global $CONFIG_DATEFORMAT;
global $WEBROOT;
$directory=$basedir.'/'.$dir;
// exit if try to access files outside our directory
if(strstr($dir,'..')<>false) exit();
$directory=realpath($directory);
$dirs=explode('/',$dir);
// breadcrumb
if(count($dirs)>1) {
echo('
');
echo('home | ');
$currentdir='';
foreach($dirs as $d) {
$currentdir.='/'.$d.'';
if($d<>'') echo(' '.$d.' | ');
}
echo('
');
}
// files and directories
echo('');
$filesfound=false;
$content=self::getdirectorycontent($directory);
if($content){
foreach($content as $file){
echo('');
OC_UTIL::showicon($file['type']);
if($file['type']=='dir') echo(''.$file['name'].' | ');
if($file['type']<>'dir') echo(''.$file['name'].' | ');
if($file['type']<>'dir') echo(''.$file['size'].' byte | '); else echo(' | ');
echo(''.date($CONFIG_DATEFORMAT,$file['mtime']).' | ');
echo('
');
}
}
echo('
');
if(!$content) echo('
no files here
');
echo('
');*/
echo '';
}
/**
* get the content of a directory
* @param dir $directory
*/
public static function getdirectorycontent($directory){
$filesfound=true;
$content=array();
$dirs=array();
$file=array();
if (is_dir($directory)) {
if ($dh = opendir($directory)) {
while (($filename = readdir($dh)) !== false) {
if($filename<>'.' and $filename<>'..'){
$file=array();
$filesfound=true;
$file['name']=$filename;
$file['directory']=$directory;
$stat=stat($directory.'/'.$filename);
$file=array_merge($file,$stat);
$file['type']=filetype($directory .'/'. $filename);
if($file['type']=='dir'){
$dirs[$file['name']]=$file;
}else{
$files[$file['name']]=$file;
}
}
}
closedir($dh);
}
}
ksort($dirs);
ksort($files);
$content=array_merge($dirs,$files);
if($filesfound){
return $content;
}else{
return false;
}
}
/**
* return the cntent of a file
*
* @param dir $dir
* @param file $file
*/
public static function get($dir,$file){
if(isset($_SESSION['username']) and $_SESSION['username']<>'') {
global $CONFIG_DATADIRECTORY;
$filename=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$file;
// exit if try to access files outside our directory
if(strstr($filename,'..')<>false) exit();
OC_LOG::event($_SESSION['username'],3,$dir.'/'.$file);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
readfile($filename);
}
exit;
}
}
?>