Example #1
0
 /**
  * Replace filesystem file with given file.
  *
  * @param \GO\Base\Fs\File $fsFile
  */
 public function replace(\GO\Base\Fs\File $fsFile, $isUploadedFile = false)
 {
     if ($this->isLocked()) {
         throw new \GO\Files\Exception\FileLocked();
     }
     //		for safety allow replace action
     //		if(!File::checkQuota($fsFile->size()-$this->size))
     //			throw new \GO\Base\Exception\InsufficientDiskSpace();
     if (!$this->isNew) {
         $this->log('edit');
     }
     $this->saveVersion();
     if (!$fsFile->move($this->folder->fsFolder, $this->name, $isUploadedFile)) {
         return false;
     }
     $fsFile->setDefaultPermissions();
     $this->mtime = $fsFile->mtime();
     $this->save();
     $this->fireEvent('replace', array($this, $isUploadedFile));
     return true;
 }
Example #2
0
 protected function actionThumb($params)
 {
     GO::session()->closeWriting();
     $dir = GO::config()->root_path . 'views/Extjs3/themes/Default/images/128x128/filetypes/';
     $url = GO::config()->host . 'views/Extjs3/themes/Default/images/128x128/filetypes/';
     $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . $params['src']);
     if (is_dir(GO::config()->file_storage_path . $params['src'])) {
         $src = $dir . 'folder.png';
     } else {
         switch (strtolower($file->extension())) {
             case 'svg':
             case 'ico':
             case 'jpg':
             case 'jpeg':
             case 'png':
             case 'gif':
             case 'xmind':
                 $src = GO::config()->file_storage_path . $params['src'];
                 break;
             case 'tar':
             case 'tgz':
             case 'gz':
             case 'bz2':
             case 'zip':
                 $src = $dir . 'zip.png';
                 break;
             case 'odt':
             case 'docx':
             case 'doc':
             case 'htm':
             case 'html':
                 $src = $dir . 'doc.png';
                 break;
             case 'odc':
             case 'ods':
             case 'xls':
             case 'xlsx':
                 $src = $dir . 'spreadsheet.png';
                 break;
             case 'odp':
             case 'pps':
             case 'pptx':
             case 'ppt':
                 $src = $dir . 'pps.png';
                 break;
             case 'eml':
                 $src = $dir . 'message.png';
                 break;
             case 'log':
                 $src = $dir . 'txt.png';
                 break;
             default:
                 if (file_exists($dir . $file->extension() . '.png')) {
                     $src = $dir . $file->extension() . '.png';
                 } else {
                     $src = $dir . 'unknown.png';
                 }
                 break;
         }
     }
     $file = new \GO\Base\Fs\File($src);
     if ($file->size() > \GO::config()->max_thumbnail_size * 1024 * 1024) {
         throw new \Exception("Image may not be larger than 5MB.");
     }
     $w = isset($params['w']) ? intval($params['w']) : 0;
     $h = isset($params['h']) ? intval($params['h']) : 0;
     $zc = !empty($params['zc']) && !empty($w) && !empty($h);
     $lw = isset($params['lw']) ? intval($params['lw']) : 0;
     $lh = isset($params['lh']) ? intval($params['lh']) : 0;
     $pw = isset($params['pw']) ? intval($params['pw']) : 0;
     $ph = isset($params['ph']) ? intval($params['ph']) : 0;
     if ($file->extension() == 'xmind') {
         //			$filename = $file->nameWithoutExtension().'.jpeg';
         //
         //			if (!file_exists($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename) || filectime($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename) < filectime($GLOBALS['GO_CONFIG']->file_storage_path . $path)) {
         //				$zipfile = zip_open($GLOBALS['GO_CONFIG']->file_storage_path . $path);
         //
         //				while ($entry = zip_read($zipfile)) {
         //					if (zip_entry_name($entry) == 'Thumbnails/thumbnail.jpg') {
         //						require_once($GLOBALS['GO_CONFIG']->class_path . 'filesystem.class.inc');
         //						zip_entry_open($zipfile, $entry, 'r');
         //						file_put_contents($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename, zip_entry_read($entry, zip_entry_filesize($entry)));
         //						zip_entry_close($entry);
         //						break;
         //					}
         //				}
         //				zip_close($zipfile);
         //			}
         //			$path = 'thumbcache/' . $filename;
     }
     $cacheDir = new \GO\Base\Fs\Folder(GO::config()->orig_tmpdir . 'thumbcache');
     $cacheDir->create();
     $cacheFilename = str_replace(array('/', '\\'), '_', $file->parent()->path() . '_' . $w . '_' . $h . '_' . $lw . '_' . $ph . '_' . '_' . $pw . '_' . $lw);
     if ($zc) {
         $cacheFilename .= '_zc';
     }
     //$cache_filename .= '_'.filesize($full_path);
     $cacheFilename .= $file->name();
     $readfile = $cacheDir->path() . '/' . $cacheFilename;
     $thumbExists = file_exists($cacheDir->path() . '/' . $cacheFilename);
     $thumbMtime = $thumbExists ? filemtime($cacheDir->path() . '/' . $cacheFilename) : 0;
     GO::debug("Thumb mtime: " . $thumbMtime . " (" . $cacheFilename . ")");
     if (!empty($params['nocache']) || !$thumbExists || $thumbMtime < $file->mtime() || $thumbMtime < $file->ctime()) {
         GO::debug("Resizing image");
         $image = new \GO\Base\Util\Image($file->path());
         if (!$image->load_success) {
             GO::debug("Failed to load image for thumbnailing");
             //failed. Stream original image
             $readfile = $file->path();
         } else {
             if ($zc) {
                 $image->zoomcrop($w, $h);
             } else {
                 if ($lw || $lh || $pw || $lw) {
                     //treat landscape and portrait differently
                     $landscape = $image->landscape();
                     if ($landscape) {
                         $w = $lw;
                         $h = $lh;
                     } else {
                         $w = $pw;
                         $h = $ph;
                     }
                 }
                 GO::debug($w . "x" . $h);
                 if ($w && $h) {
                     $image->resize($w, $h);
                 } elseif ($w) {
                     $image->resizeToWidth($w);
                 } else {
                     $image->resizeToHeight($h);
                 }
             }
             $image->save($cacheDir->path() . '/' . $cacheFilename);
         }
     }
     header("Expires: " . date("D, j M Y G:i:s ", time() + 86400 * 365) . 'GMT');
     //expires in 1 year
     header('Cache-Control: cache');
     header('Pragma: cache');
     header('Content-Type: ' . $file->mimeType());
     header('Content-Disposition: inline; filename="' . $cacheFilename . '"');
     header('Content-Transfer-Encoding: binary');
     readfile($readfile);
     //			case 'pdf':
     //				$this->redirect($url . 'pdf.png');
     //				break;
     //
     //			case 'tar':
     //			case 'tgz':
     //			case 'gz':
     //			case 'bz2':
     //			case 'zip':
     //				$this->redirect( $url . 'zip.png');
     //				break;
     //			case 'odt':
     //			case 'docx':
     //			case 'doc':
     //				$this->redirect( $url . 'doc.png');
     //				break;
     //
     //			case 'odc':
     //			case 'ods':
     //			case 'xls':
     //			case 'xlsx':
     //				$this->redirect( $url . 'spreadsheet.png');
     //				break;
     //
     //			case 'odp':
     //			case 'pps':
     //			case 'pptx':
     //			case 'ppt':
     //				$this->redirect( $url . 'pps.png');
     //				break;
     //			case 'eml':
     //				$this->redirect( $url . 'message.png');
     //				break;
     //
     //			case 'htm':
     //				$this->redirect( $url . 'doc.png');
     //				break;
     //
     //			case 'log':
     //				$this->redirect( $url . 'txt.png');
     //				break;
     //
     //			default:
     //				if (file_exists($dir . $file->extension() . '.png')) {
     //					$this->redirect( $url . $file->extension() . '.png');
     //				} else {
     //					$this->redirect( $url . 'unknown.png');
     //				}
     //				break;
 }
Example #3
0
 /**
  * Output the right headers for outputting file data to a browser.
  * 
  * @param \GO\Base\Fs\File $file Use \GO\Base\Fs\MemoryFile for outputting variables
  * @param boolean $inline
  * @param boolean $cache Cache the file for one day in the browser.
  * @param array $extraHeaders  Key value array for extra headers
  */
 public static function outputDownloadHeaders(\GO\Base\Fs\File $file, $inline = true, $cache = false, $extraHeaders = array())
 {
     header('Content-Transfer-Encoding: binary');
     $disposition = $inline ? 'inline' : 'attachment';
     if ($cache) {
         header("Expires: " . date("D, j M Y G:i:s ", time() + 86400) . 'GMT');
         //expires in 1 day
         header('Cache-Control: cache');
         header('Pragma: cache');
     }
     if (Http::isInternetExplorer()) {
         header('Content-Type: application/download');
         header('Content-Disposition: ' . $disposition . '; filename="' . rawurlencode($file->name()) . '"');
         if (!$cache) {
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
         }
     } else {
         header('Content-Type: ' . $file->mimeType());
         header('Content-Disposition: ' . $disposition . '; filename="' . $file->name() . '"');
         if (!$cache) {
             header('Pragma: no-cache');
         }
     }
     if ($file->exists()) {
         if ($file->extension() != 'zip') {
             //Don't set content lenght for zip files because gzip of apache will corrupt the download. http://www.heath-whyte.info/david/computers/corrupted-zip-file-downloads-with-php
             header('Content-Length: ' . $file->size());
         }
         header("Last-Modified: " . gmdate("D, d M Y H:i:s", $file->mtime()) . " GMT");
         header("ETag: " . $file->md5Hash());
     }
     foreach ($extraHeaders as $header => $value) {
         header($header . ': ' . $value);
     }
 }