Esempio n. 1
0
 }
 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);
     } else {
         if ($kfm_only_allow_image_upload && !getimagesize($to)) {
             $errors[] = 'only images may be uploaded';
             unlink($to);
         } else {
             chmod($to, octdec('0' . $kfm_default_upload_permission));
             $fid = kfmFile::addToDb($filename, $kfm_session->get('cwd_id'));
             $file = kfmFile::getInstance($fid);
             if (function_exists('exif_imagetype')) {
                 $imgtype = @exif_imagetype($to);
                 if ($imgtype) {
                     $file = kfmImage::getInstance($file);
                     $comment = '';
                     if ($imgtype == 1) {
                         // gif
                         $fc = file_get_contents($to);
                         $arr = explode('!', $fc);
                         $found = 0;
                         for ($i = 0; $i < count($arr) && !$found; ++$i) {
                             $block = $arr[$i];
                             if (substr($block, 0, 2) == chr(254) . chr(21)) {
                                 $found = 1;
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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;
 }