Exemplo n.º 1
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;
 }
if ($ren_old_name = SpawVars::getPostVar('rename_from') and $ren_new_name = SpawVars::getPostVar('rename_to')) {
    // cleanup/filter file/directory names
    $ren_old_name = basename($ren_old_name);
    $ren_new_name = basename(trim($ren_new_name));
    // check if file/directory can be renamed
    if (!file_exists($spawfm->getCurrentFsDir() . $ren_old_name)) {
        $error_msg = $lang->m('error_rename_file_missing', 'spawfm');
    } elseif (is_dir($spawfm->getCurrentFsDir() . $ren_old_name) and !$spawfm->getCurrentDirSetting('allow_modify_subdirectories')) {
        $error_msg = $lang->m('error_rename_directories_forbidden', 'spawfm');
    } elseif (!is_dir($spawfm->getCurrentFsDir() . $ren_old_name) and !$spawfm->getCurrentDirSetting('allow_modify')) {
        $error_msg = $lang->m('error_rename_forbidden', 'spawfm');
    } elseif (file_exists($spawfm->getCurrentFsDir() . $ren_new_name)) {
        $error_msg = str_replace('[*FILE*]', $ren_new_name, $lang->m('error_rename_file_exists', 'spawfm'));
    } else {
        // check if filetype doesn't change
        if ($spawfm->getFileExtension($ren_old_name) != $spawfm->getFileExtension($ren_new_name)) {
            $error_msg = $lang->m('error_rename_extension_changed', 'spawfm');
        } elseif (!@rename($spawfm->getCurrentFsDir() . $ren_old_name, $spawfm->getCurrentFsDir() . $ren_new_name)) {
            $error_msg = $lang->m('error_rename_failed', 'spawfm');
        }
    }
}
// handle new directory creation
if ($dir_name = SpawVars::getPostVar('new_folder')) {
    if ($spawfm->getCurrentDirSetting('recursive') and $spawfm->getCurrentDirSetting('allow_create_subdirectories')) {
        // filter dir name
        $dir_name = trim(basename($dir_name));
        if (preg_match('#[:<>|?*"/\\\\]+#', $dir_name)) {
            $error_msg = $lang->m('error_create_directories_name_invalid', 'spawfm');
        } elseif (file_exists($spawfm->getCurrentFsDir() . $dir_name)) {
            $error_msg = $lang->m('error_create_directories_name_used', 'spawfm');
Exemplo n.º 3
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;
 }