function getFiles() { $filesdb = db_fetch_all("select * from " . KFM_DB_PREFIX . "files where directory=" . $this->id); $fileshash = array(); if (is_array($filesdb)) { foreach ($filesdb as $r) { $fileshash[$r['name']] = $r['id']; } } // { get files from directoryIterator, then sort them $tmp = array(); foreach (new directoryIterator($this->path()) as $f) { if ($f->isDot()) { continue; } if (is_file($this->path() . $f) && kfmFile::checkName($f)) { $tmp[] = $f . ''; } } natsort($tmp); // } // { load file details from database $files = array(); foreach ($tmp as $filename) { if (!isset($fileshash[$filename])) { $fileshash[$filename] = kfmFile::addToDb($filename, $this->id); } $file = kfmFile::getInstance($fileshash[$filename]); if (!$file) { continue; } if ($file->isImage()) { $file = kfmImage::getInstance($fileshash[$filename]); if ($this->maxWidth > 0 && $this->maxHeight > 0 && ($file->width > $this->maxWidth || $file->height > $this->maxHeight)) { $file->resize($this->maxWidth, $this->maxHeight); } } $files[] = $file; unset($fileshash[$filename]); } // } return $files; }
function _zip($filename, $files) { global $kfm_session; $cwd_id = $kfm_session->get('cwd_id'); $dir = kfmDirectory::getInstance($cwd_id); $cwd = $dir->path(); if (!$kfm->setting('allow_file_create')) { return kfm_error(kfm_lang('permissionDeniedCreateFile')); } global $rootdir; if (!kfmFile::checkName($filename)) { return kfm_error(kfm_lang('illegalFileName', $filename)); } $arr = array(); foreach ($files as $f) { $file = kfmFile::getInstance($f); if (!$file) { return kfm_error(kfm_lang('missingFileInSelection')); } $arr[] = $file->path; } # try native system zip command $res = -1; $pdir = $cwd . '/'; $zipfile = $pdir . $filename; for ($i = 0; $i < count($arr); ++$i) { $arr[$i] = str_replace($pdir, '', $arr[$i]); } exec('cd "' . escapeshellcmd($cwd) . '" && zip -D "' . escapeshellcmd($zipfile) . '" "' . join('" "', $arr) . '"', $arr, $res); if ($res) { return kfm_error(kfm_lang('noNativeZipCommand')); } return kfm_loadFiles($cwd_id); }
/** * Rename the file * @param string $newName new file name */ function rename($newName) { if (!$GLOBALS['kfm']->setting('allow_file_edit')) { return $this->error(kfm_lang('permissionDeniedEditFile')); } if (!kfmFile::checkName($newName)) { return $this->error(kfm_lang('cannotRenameFromTo', $this->name, $newName)); } $newFileAddress = $this->directory . $newName; if (file_exists($newFileAddress)) { return $this->error(kfm_lang('fileAlreadyExists')); } rename($this->path, $newFileAddress); $this->name = $newName; $this->path = $newFileAddress; $GLOBALS['kfm']->db->query("UPDATE " . KFM_DB_PREFIX . "files SET name='" . sql_escape($newName) . "' WHERE id=" . $this->id); }
require_once 'initialise.php'; $errors = array(); if ($kfm_allow_file_upload) { $file = isset($_FILES['kfm_file']) ? $_FILES['kfm_file'] : $_FILES['Filedata']; $filename = $file['name']; $tmpname = $file['tmp_name']; $cwd = $kfm_session->get('cwd_id'); if (!$cwd) { $errors[] = kfm_lang('CWD not set'); } else { $toDir = kfmDirectory::getInstance($cwd); $to = $toDir->path . '/' . $filename; if (!is_file($tmpname)) { $errors[] = 'No file uploaded'; } else { if (!kfmFile::checkName($filename)) { $errors[] = 'The filename: ' . $filename . ' is not allowed'; } } } if ($cwd == 1 && !$kfm_allow_files_in_root) { $errors[] = 'Cannot upload files to the root directory'; } if (file_exists($to)) { $errors[] = 'File already exists'; } // TODO new string if (!count($errors)) { move_uploaded_file($tmpname, $to); if (!file_exists($to)) { $errors[] = kfm_lang('failedToSaveTmpFile', $tmpname, $to);
function getFiles() { $this->handle = opendir($this->path); if (!$this->handle) { return $this->error('unable to open directory'); } $filesdb = db_fetch_all("select * from " . KFM_DB_PREFIX . "files where directory=" . $this->id); $fileshash = array(); if (is_array($filesdb)) { foreach ($filesdb as $r) { $fileshash[$r['name']] = $r['id']; } } $files = array(); while (false !== ($filename = readdir($this->handle))) { if (is_file($this->path . $filename) && kfmFile::checkName($filename)) { if (!isset($fileshash[$filename])) { $fileshash[$filename] = kfmFile::addToDb($filename, $this->id); } $file = kfmFile::getInstance($fileshash[$filename]); if (!$file) { continue; } if ($file->isImage()) { $file = kfmImage::getInstance($fileshash[$filename]); } $files[] = $file; unset($fileshash[$filename]); } } closedir($this->handle); return $files; }