print_r($var);
    echo '</pre>';
}
/////////////////////////////////////
$lang->setModule('spawfm');
// load environment variables
$settings = $config->getConfigValue('PG_SPAWFM_SETTINGS');
$filetypes = $config->getConfigValue('PG_SPAWFM_FILETYPES');
$dir_list = $config->getConfigValue('PG_SPAWFM_DIRECTORIES');
$doc_root = $config->getConfigValue('DOCUMENT_ROOT');
if (preg_match('|[\\/]$|', $doc_root)) {
    $doc_root = substr($doc_root, 0, -1);
}
$imgdir = $config->getConfigValue('SPAW_DIR') . 'plugins/spawfm/lib/theme/' . $theme->name . '/images/';
require_once $config->getConfigValue('SPAW_ROOT') . 'plugins/spawfm/class/spawfm.class.php';
$spawfm = new SpawFm();
$error_msg = '';
// set default "global" settings if not set by user
if (!isset($settings['allow_upload'])) {
    $settings['allow_upload'] = false;
}
if (!isset($settings['allow_modify'])) {
    $settings['allow_modify'] = false;
}
if (!isset($settings['max_upload_filesize'])) {
    $settings['max_upload_filesize'] = 0;
}
if (!isset($settings['allowed_filetypes'])) {
    $settings['allowed_filetypes'] = array('any');
}
if (!isset($settings['chmod_to'])) {
Example #2
0
    print_r($var);
    echo '</pre>';
}
/////////////////////////////////////
$lang->setModule('spawfm');
// load environment variables
$settings = $config->getConfigValue('PG_SPAWFM_SETTINGS');
$filetypes = $config->getConfigValue('PG_SPAWFM_FILETYPES');
$dir_list = $config->getConfigValue('PG_SPAWFM_DIRECTORIES');
$doc_root = $config->getConfigValue('DOCUMENT_ROOT');
if (preg_match('|[\\/]$|', $doc_root)) {
    $doc_root = substr($doc_root, 0, -1);
}
$imgdir = $config->getConfigValue('SPAW_DIR') . 'plugins/spawfm/lib/theme/' . $theme->name . '/img/';
require_once $config->getConfigValue('SPAW_ROOT') . 'plugins/spawfm/class/spawfm.class.php';
$spawfm = new SpawFm();
$error_msg = '';
// set default "global" settings if not set by user
if (!isset($settings['allow_upload'])) {
    $settings['allow_upload'] = false;
}
if (!isset($settings['allow_modify'])) {
    $settings['allow_modify'] = false;
}
if (!isset($settings['max_upload_filesize'])) {
    $settings['max_upload_filesize'] = 0;
}
if (!isset($settings['allowed_filetypes'])) {
    $settings['allowed_filetypes'] = array('any');
}
if (!isset($settings['chmod_to'])) {
Example #3
0
 function uploadFile($uplfile)
 {
     global $lang;
     // check if upload is allowed
     if (!$this->getCurrentDirSetting('allow_upload')) {
         $this->setError($lang->m('error_upload_forbidden', 'spawfm'));
     } else {
         if (is_uploaded_file($uplfile['tmp_name'])) {
             // check filetype
             $ext = SpawFm::getFileExtension($uplfile['name']);
             $allowed_ext = $this->getAllowedExtensions();
             if ((in_array('.*', $allowed_ext) or in_array($ext, $allowed_ext)) and $this->isSecureFile($uplfile['name'])) {
                 // check filesize
                 if (!$this->getCurrentDirSetting('max_upload_filesize') or $uplfile['size'] <= $this->getCurrentDirSetting('max_upload_filesize')) {
                     $ok = true;
                     $err = array();
                     /*
                       check image dimensions: try to read image dimensions (this step is 
                       omitted if getimagesize() does not recognize file as image or fails 
                       to read it's dimensions
                     */
                     if (($this->getCurrentDirSetting('max_img_width') or $this->getCurrentDirSetting('max_img_height')) and $imgsize = @getimagesize($uplfile['tmp_name'])) {
                         // check if dimensions not too big if specified
                         if ($this->getCurrentDirSetting('max_img_width') and $imgsize[0] > $this->getCurrentDirSetting('max_img_width')) {
                             $ok = false;
                             $err[] = str_replace('[*MAXWIDTH*]', $this->getCurrentDirSetting('max_img_width'), $lang->m('error_img_width_max', 'spawfm'));
                         }
                         if ($this->getCurrentDirSetting('max_img_height') and $imgsize[0] > $this->getCurrentDirSetting('max_img_height')) {
                             $ok = false;
                             $err[] = str_replace('[*MAXHEIGHT*]', $this->getCurrentDirSetting('max_img_height'), $lang->m('error_img_height_max', 'spawfm'));
                         }
                     }
                     if (!$ok) {
                         $this->setError(implode('<br />', $err));
                     } else {
                         // proceed saving uploaded file
                         $uplfile_name = $uplfile['name'];
                         $i = 1;
                         // pick unused file name
                         while (file_exists($this->getCurrentFsDir() . $uplfile_name)) {
                             $uplfile_name = ereg_replace('(.*)(\\.[a-zA-Z]+)$', '\\1_' . $i . '\\2', $uplfile['name']);
                             $i++;
                         }
                         if (!@move_uploaded_file($uplfile['tmp_name'], $this->getCurrentFsDir() . $uplfile_name)) {
                             $this->setError($lang->m('error_upload_failed', 'spawfm'));
                         } else {
                             if (strlen($this->getCurrentDirSetting('chmod_to'))) {
                                 // chmod uploaded file
                                 if (!@chmod($this->getCurrentFsDir() . $uplfile_name, $this->getCurrentDirSetting('chmod_to'))) {
                                     $this->setError($lang->m('error_chmod_uploaded_file', 'spawfm'));
                                 }
                             }
                         }
                     }
                 } else {
                     $this->setError($lang->m('error_max_filesize', 'spawfm') . ' ' . round($this->getCurrentDirSetting('max_upload_filesize') / 1024, 2) . ' KB');
                 }
             } else {
                 $this->setError($lang->m('error_bad_filetype', 'spawfm'));
             }
         } else {
             if ($uplfile['error'] == 1 or $uplfile['error'] == 2) {
                 $this->setError($lang->m('error_upload_file_too_big', 'spawfm'));
             } elseif ($uplfile['error'] == 3) {
                 $this->setError($lang->m('error_upload_file_incomplete', 'spawfm'));
             } else {
                 $this->setError($lang->m('error_upload_failed', 'spawfm'));
             }
         }
     }
     return $this->error() ? false : $uplfile_name;
 }
Example #4
0
 function getFilesList()
 {
     global $lang;
     $files = array();
     if (!$this->getCurrentFsDir()) {
         return $files;
     }
     $allowed_ext = $this->getAllowedExtensions();
     if ($dh = @opendir($this->getCurrentFsDir())) {
         while (false !== ($file = readdir($dh))) {
             if (!is_dir($this->getCurrentFsDir() . $file)) {
                 $ext = SpawFm::getFileExtension($file);
                 if (in_array('.*', $allowed_ext) or in_array($ext, $allowed_ext)) {
                     $files[] = $file;
                 }
             }
         }
         closedir($dh);
     } else {
         return false;
     }
     // reorder files by title
     sort($files, SORT_STRING);
     // load files' details
     foreach ($files as $key => $file) {
         $ext = SpawFm::getFileExtension($file);
         if (!strlen($fdescr = $lang->m($ext, 'filetypes'))) {
             $fdescr = strtoupper(substr($ext, 1)) . ' ' . $lang->m('filetype_suffix', 'file_details');
         }
         // additional info
         if ($imgsize = @getimagesize($this->getCurrentFsDir() . $file)) {
             $other = $lang->m('img_dimensions', 'file_details') . ': ' . $imgsize[0] . 'x' . $imgsize[1];
         } else {
             $other = '';
         }
         // get thumbail
         // TO DO
         $files[$key] = array('type' => 'F', 'name' => $file, 'size' => $this->getFileSize($file), 'date' => $this->getFileDate($file), 'fdescr' => $fdescr, 'icon' => '../plugins/spawfm/img/' . $this->getFileIcon($file), 'icon_big' => '../plugins/spawfm/img/' . $this->getFileIconBig($file), 'thumb' => $this->getFileThumbnail($file), 'other' => $other);
     }
     return $files;
 }