示例#1
0
 public function actionAttachment($params)
 {
     GO::session()->closeWriting();
     $file = new \GO\Base\Fs\File('/dummypath/' . $params['filename']);
     $account = Account::model()->findByPk($params['account_id']);
     //$imapMessage = \GO\Email\Model\ImapMessage::model()->findByUid($account, $params['mailbox'], $params['uid']);
     if ($file->extension() == 'dat') {
         return $this->_tnefAttachment($params, $account);
     }
     $inline = true;
     if (isset($params['inline']) && $params['inline'] == 0) {
         $inline = false;
     }
     //to work around office bug: http://support.microsoft.com/kb/2019105/en-us
     //never use inline on IE with office documents because it will prompt for authentication.
     $officeExtensions = array('doc', 'dot', 'docx', 'dotx', 'docm', 'dotm', 'xls', 'xlt', 'xla', 'xlsx', 'xltx', 'xlsm', 'xltm', 'xlam', 'xlsb', 'ppt', 'pot', 'pps', 'ppa', 'pptx', 'potx', 'ppsx', 'ppam', 'pptm', 'potm', 'ppsm');
     if (\GO\Base\Util\Http::isInternetExplorer() && in_array($file->extension(), $officeExtensions)) {
         $inline = false;
     }
     $imap = $account->openImapConnection($params['mailbox']);
     \GO\Base\Util\Http::outputDownloadHeaders($file, $inline, true);
     $fp = fopen("php://output", 'w');
     $imap->get_message_part_decoded($params['uid'], $params['number'], $params['encoding'], false, true, false, $fp);
     fclose($fp);
 }
示例#2
0
 private function _duplicateFileColumns(ActiveRecord $duplicate)
 {
     foreach ($this->columns as $column => $attr) {
         if ($attr['gotype'] == 'file') {
             if (!empty($this->_attributes[$column])) {
                 $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . $this->_attributes[$column]);
                 $tmpFile = \GO\Base\Fs\File::tempFile('', $file->extension());
                 $file->copy($tmpFile->parent(), $tmpFile->name());
                 $duplicate->{$column} = $tmpFile;
             }
         }
     }
 }
示例#3
0
 public function actionPasteUploadTemporary($filename, $filetype)
 {
     $type = explode('/', $filetype);
     $extension = $type[1];
     $_FILES['pastedFile']['name'] = $filename . '.' . $extension;
     $file = new GO\Base\Fs\File($_FILES['pastedFile']['tmp_name']);
     $file->move(GO::config()->getTempFolder(), $filename . '.' . $extension, true);
     $response = new \GO\Base\Data\JsonResponse(array('success' => true, 'data' => array('tmp_file' => $file->stripTempPath(), 'name' => $file->name(), 'size' => $file->size(), 'type' => $file->mimeType(), 'extension' => $file->extension(), 'human_size' => $file->humanSize(), 'from_file_storage' => false)));
     echo $response;
 }
示例#4
0
 /**
  * Set new photo file. The file will be converted into JPEG and resized to fit
  * a 480x640 pixel box
  * 
  * @param \GO\Base\Fs\File $file
  */
 public function seOLDPhoto(\GO\Base\Fs\File $file)
 {
     if ($this->isNew) {
         throw new \Exception("Cannot save a photo on a new company that is not yet saved.");
     }
     $this->getPhotoFile()->delete();
     $photoPath = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'company_photos/' . $this->addressbook_id . '/');
     $photoPath->create();
     //		if(strtolower($file->extension())!='jpg'){
     //		$filename = $photoPath->path().'/'.$this->id.'.jpg';
     //		$img = new \GO\Base\Util\Image();
     //		if(!$img->load($file->path())){
     //			throw new \Exception(\GO::t('imageNotSupported','addressbook'));
     //		}
     //
     //		//resize it to small image so we don't get in trouble with sync clients
     //		$img->fitBox(240,320);
     //
     //		if(!$img->save($filename, IMAGETYPE_JPEG)){
     //			throw new \Exception("Could not save photo!");
     //		}
     //		$file = new \GO\Base\Fs\File($filename);
     //		}else
     //		{
     $file->move($photoPath, $this->id . '.' . strtolower($file->extension()));
     //		}
     $this->photo = $file->stripFileStoragePath();
 }
示例#5
0
文件: Http.php 项目: ajaboa/crmpuan
 /**
  * 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);
     }
 }
示例#6
0
 protected function actionDecompress($params)
 {
     if (!\GO\Base\Util\Common::isWindows()) {
         putenv('LANG=en_US.UTF-8');
     }
     $sources = json_decode($params['decompress_sources'], true);
     $workingFolder = \GO\Files\Model\Folder::model()->findByPk($params['working_folder_id']);
     $workingPath = \GO::config()->file_storage_path . $workingFolder->path;
     chdir($workingPath);
     while ($filePath = array_shift($sources)) {
         $file = new \GO\Base\Fs\File(\GO::config()->file_storage_path . $filePath);
         switch (strtolower($file->extension())) {
             case 'zip':
                 $folder = \GO\Base\Fs\Folder::tempFolder(uniqid());
                 if (class_exists("\\ZipArchive")) {
                     $zip = new \ZipArchive();
                     $zip->open($file->path());
                     $zip->extractTo($folder->path());
                     $this->_convertZipEncoding($folder);
                 } else {
                     chdir($folder->path());
                     $cmd = \GO::config()->cmd_unzip . ' -n ' . escapeshellarg($file->path());
                     exec($cmd, $output, $ret);
                     if ($ret != 0) {
                         throw new \Exception("Could not decompress\n" . implode("\n", $output));
                     }
                 }
                 $items = $folder->ls();
                 foreach ($items as $item) {
                     $item->move(new \GO\Base\Fs\Folder($workingPath));
                 }
                 $folder->delete();
                 break;
             case 'gz':
             case 'tgz':
                 $cmd = \GO::config()->cmd_tar . ' zxf ' . escapeshellarg($file->path());
                 exec($cmd, $output, $ret);
                 if ($ret != 0) {
                     throw new \Exception("Could not decompress\n" . implode("\n", $output));
                 }
                 break;
             case 'tar':
                 $cmd = \GO::config()->cmd_tar . ' xf ' . escapeshellarg($file->path());
                 exec($cmd, $output, $ret);
                 if ($ret != 0) {
                     throw new \Exception("Could not decompress\n" . implode("\n", $output));
                 }
                 break;
         }
     }
     $workingFolder->syncFilesystem(true);
     return array('success' => true);
 }