Source for file filemanager.class.php
Documentation is available at filemanager.class.php
* class for the filemanager.php connector
* @author Riaan Los <mail (at) riaanlos (dot) nl>
* @author Simon Georget <simon (at) linea21 (dot) com>
* @package linea21.externals
* @subpackage Filemanager
protected $get = array();
protected $post = array();
protected $item = array();
if (isset ($this->config['doc_root'])) {
$this->doc_root = $_SERVER['DOCUMENT_ROOT'];
$this->availableLanguages();
$this->loadLanguageFile();
public function error($string,$textarea= false) {
echo '<textarea>' . json_encode($array) . '</textarea>';
public function lang($string) {
return 'Language string error on ' . $string;
public function getvar($var) {
if(!isset ($_GET[$var]) || $_GET[$var]== '') {
$this->get[$var] = $this->sanitize($_GET[$var]);
if(!isset ($_POST[$var]) || $_POST[$var]== '') {
$this->post[$var] = $_POST[$var];
'Path'=> $this->get['path'],
'Filename'=> $this->item['filename'],
'File Type'=> $this->item['filetype'],
'Preview'=> $this->item['preview'],
'Properties'=> $this->item['properties'],
if(!$handle = opendir($current_path)) {
while (false !== ($file = readdir($handle))) {
if($file != "." && $file != "..") {
sort($filesDir); // sorting by names
// Sort files by modified time, latest to earliest
// Use SORT_ASC in place of SORT_DESC for earliest to latest
// array_map( 'filemtime', $filesDir ),
foreach($filesDir as $file) {
if(is_dir($current_path . $file)) {
$array[$this->get['path'] . $file . '/'] = array(
'Path'=> $this->get['path'] . $file . '/',
'Preview'=> $this->config['icons']['path'] . $this->config['icons']['directory'],
$this->get_file_info($this->get['path'] . $file);
$array[$this->get['path'] . $file] = array(
'Path'=> $this->get['path'] . $file,
'Filename'=> $this->item['filename'],
'File Type'=> $this->item['filetype'],
'Preview'=> $this->item['preview'],
'Properties'=> $this->item['properties'],
$filename = $tmp[(sizeof($tmp)- 1)];
'Old Path'=> $this->get['old'],
'New Path'=> $path . '/' . $this->get['new']. $suffix,
'New Name'=> $this->get['new']
'Path'=> $this->get['path']
'Path'=> $this->get['path']
if(!isset ($_FILES['newfile']) || !is_uploaded_file($_FILES['newfile']['tmp_name'])) {
if(($this->config['upload']['size']!= false && is_numeric($this->config['upload']['size'])) && ($_FILES['newfile']['size'] > ($this->config['upload']['size'] * 1024 * 1024))) {
if($this->config['upload']['imagesonly'] || (isset ($this->params['type']) && strtolower($this->params['type'])== 'images')) {
if(!($size = @getimagesize($_FILES['newfile']['tmp_name']))){
if(!in_array($size[2], array(1, 2, 3, 7, 8))) {
$_FILES['newfile']['name'] = $this->cleanString($_FILES['newfile']['name'],array('.','-'));
if(!$this->config['upload']['overwrite']) {
$_FILES['newfile']['name'] = $this->checkFilename($this->doc_root . $this->post['currentpath'],$_FILES['newfile']['name']);
chmod($this->doc_root . $this->post['currentpath'] . $_FILES['newfile']['name'], 0644);
'Path'=> $this->post['currentpath'],
'Name'=> $_FILES['newfile']['name'],
echo '<textarea>' . json_encode($response) . '</textarea>';
'Parent'=> $this->get['path'],
'Name'=> $this->get['name'],
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
private function setParams() {
$tmp = (isset ($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/');
if(isset ($tmp[1]) && $tmp[1]!= '') {
$params_tmp = explode('&',$tmp[1]);
foreach($params_tmp as $value) {
if(isset ($tmp[0]) && $tmp[0]!= '' && isset ($tmp[1]) && $tmp[1]!= '') {
$params[$tmp[0]] = $tmp[1];
private function get_file_info($path= '',$return= array()) {
$this->item['preview'] = $this->config['icons']['path'] . $this->config['icons']['default'];
$this->item['preview'] = $this->config['icons']['path'] . $this->config['icons']['directory'];
$this->item['preview'] = 'connectors/php/filemanager.php?mode=preview&path=' . rawurlencode($path);
//if(isset($get['getsize']) && $get['getsize']=='true') {
if ($this->item['properties']['Size']) {
$this->item['properties']['Size'] = 0;
list ($width, $height) = array(0, 0);
$this->item['properties']['Height'] = $height;
$this->item['properties']['Width'] = $width;
if (!$this->item['properties']['Size']) $this->item['properties']['Size'] = 0;
$this->item['properties']['Date Modified'] = date($this->config['date'], $this->item['filemtime']);
//$return['properties']['Date Created'] = date($config['date'], $return['filectime']); // PHP cannot get create timestamp
private function unlinkRecursive($dir,$deleteRootToo= true) {
while (false !== ($obj = readdir($dh))) {
if($obj == '.' || $obj == '..') {
if (!@unlink($dir . '/' . $obj)) {
$this->unlinkRecursive($dir. '/'. $obj, true);
private function cleanString($string, $allowed = array()) {
foreach ($allowed as $value) {
'Š'=> 'S', 'š'=> 's', 'Đ'=> 'Dj', 'đ'=> 'dj', 'Ž'=> 'Z', 'ž'=> 'z', 'Č'=> 'C', 'č'=> 'c', 'Ć'=> 'C', 'ć'=> 'c',
'À'=> 'A', 'Á'=> 'A', 'Â'=> 'A', 'Ã'=> 'A', 'Ä'=> 'A', 'Å'=> 'A', 'Æ'=> 'A', 'Ç'=> 'C', 'È'=> 'E', 'É'=> 'E',
'Ê'=> 'E', 'Ë'=> 'E', 'Ì'=> 'I', 'Í'=> 'I', 'Î'=> 'I', 'Ï'=> 'I', 'Ñ'=> 'N', 'Ò'=> 'O', 'Ó'=> 'O', 'Ô'=> 'O',
'Õ'=> 'O', 'Ö'=> 'O', 'Ő'=> 'O', 'Ø'=> 'O', 'Ù'=> 'U', 'Ú'=> 'U', 'Û'=> 'U', 'Ü'=> 'U', 'Ű'=> 'U', 'Ý'=> 'Y',
'Þ'=> 'B', 'ß'=> 'Ss','à'=> 'a', 'á'=> 'a', 'â'=> 'a', 'ã'=> 'a', 'ä'=> 'a', 'å'=> 'a', 'æ'=> 'a', 'ç'=> 'c',
'è'=> 'e', 'é'=> 'e', 'ê'=> 'e', 'ë'=> 'e', 'ì'=> 'i', 'í'=> 'i', 'î'=> 'i', 'ï'=> 'i', 'ð'=> 'o', 'ñ'=> 'n',
'ò'=> 'o', 'ó'=> 'o', 'ô'=> 'o', 'õ'=> 'o', 'ö'=> 'o', 'ő'=> 'o', 'ø'=> 'o', 'ù'=> 'u', 'ú'=> 'u', 'ű'=> 'u',
'û'=> 'u', 'ý'=> 'y', 'ý'=> 'y', 'þ'=> 'b', 'ÿ'=> 'y', 'Ŕ'=> 'R', 'ŕ'=> 'r', ' '=> '_', "'"=> '_', '/'=> ''
foreach ($string as $key => $clean) {
$clean = strtr($clean, $mapping);
$clean = preg_replace("/[^{$allow}_a-zA-Z0-9]/", '', $clean);
$cleaned[$key] = preg_replace('/[_]+/', '_', $clean); // remove double underscore
$string = strtr($string, $mapping);
$string = preg_replace("/[^{$allow}_a-zA-Z0-9]/", '', $string);
$cleaned = preg_replace('/[_]+/', '_', $string); // remove double underscore
private function sanitize($var) {
private function checkFilename($path,$filename,$i= '') {
$tmp = explode(/*$this->config['upload']['suffix'] . */$i . '.',$filename);
return $this->checkFilename($path,$filename,$i);
private function loadLanguageFile() {
// we load langCode var passed into URL if present and if exists
// else, we use default configuration var
$lang = $this->config['culture'];
if(isset ($this->params['langCode']) && in_array($this->params['langCode'], $this->languages)) $lang = $this->params['langCode'];
private function availableLanguages() {
if ($handle = opendir($this->root. '/scripts/languages/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
|