/** * Create a new instance for an ComposerMessage for example. * * @param \GO\Base\Fs\File $file The temporary file * @return \MessageAttachment */ public function createFromTempFile(\GO\Base\Fs\File $file) { // $a['name'] = $file->name(); $a = new MessageAttachment(); $a->name = $file->name(); $a->mime = $file->mimeType(); $a->setTempFile($file); $a->size = $file->size(); return $a; }
private function _processFileColumns($cols) { foreach ($cols as $column => $newValue) { $oldValue = $this->_attributes[$column]; if (empty($newValue)) { //unset of file column if (!empty($oldValue)) { $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . $oldValue); $file->delete(); $this->{$column} = ""; } } elseif ($newValue instanceof \GO\Base\Fs\File) { if (!isset($this->columns[$column]['filePathTemplate'])) { throw new \Exception('For file columns you must set a filePathTemplate'); } $destination = $this->columns[$column]['filePathTemplate']; foreach ($this->_attributes as $key => $value) { $destination = str_replace('{' . $key . '}', $value, $destination); } $destination = str_replace('{extension}', $newValue->extension(), $destination); $destinationFile = new \GO\Base\Fs\File(GO::config()->file_storage_path . $destination); $destinationFolder = $destinationFile->parent(); $destinationFolder->create(); $newValue->move($destinationFolder, $destinationFile->name()); $this->{$column} = $destinationFile->stripFileStoragePath(); } else { throw new \Exception("Column {$column} must be an instance of GO\\Base\\Fs\\File. " . var_export($newValue, true)); } } return !empty($cols); }
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; }
/** * Import a filesystem file into the database. * * @param \GO\Base\Fs\File $fsFile * @return File */ public static function importFromFilesystem(\GO\Base\Fs\File $fsFile) { $folderPath = str_replace(\GO::config()->file_storage_path, "", $fsFile->parent()->path()); $folder = Folder::model()->findByPath($folderPath, true); return $folder->hasFile($fsFile->name()) || $folder->addFile($fsFile->name()); }
/** * 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); } }
/** * The savemailas module can send attachments along to be stored as files with * a note, task, event etc. * * @param type $response * @param type $model * @param type $params */ public function processAttachments(&$response, &$model, &$params) { //Does this belong in the controller? if (!empty($params['tmp_files'])) { $tmp_files = json_decode($params['tmp_files'], true); if (count($tmp_files)) { $folder_id = $this->checkModelFolder($model, true, true); $folder = \GO\Files\Model\Folder::model()->findByPk($folder_id); while ($tmp_file = array_shift($tmp_files)) { if (!empty($tmp_file['tmp_file'])) { $file = new \GO\Base\Fs\File(\GO::config()->tmpdir . $tmp_file['tmp_file']); $file->move(new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . $folder->path)); $folder->addFile($file->name()); } } } } }
/** * Add an uploaded file * * @param array $filesArrayItem Item from the $_FILES array * @return boolean */ public function addUploadedFile($filesArrayItem) { $fsFile = new \GO\Base\Fs\File($filesArrayItem['tmp_name']); $fsFile->move($this->fsFolder, $filesArrayItem['name'], true, true); return $this->addFile($fsFile->name()); }
private function _decryptFile(\GO\Base\Fs\File $srcFile, \GO\Email\Model\Account $account) { $data = $srcFile->getContents(); if (strpos($data, "enveloped-data") || strpos($data, 'Encrypted Message')) { $cert = \GO\Smime\Model\Certificate::model()->findByPk($account->id); $password = \GO::session()->values['smime']['passwords'][$_REQUEST['account_id']]; openssl_pkcs12_read($cert->cert, $certs, $password); $decryptedFile = \GO\Base\Fs\File::tempFile(); $ret = openssl_pkcs7_decrypt($srcFile->path(), $decryptedFile->path(), $certs['cert'], array($certs['pkey'], $password)); if (!$decryptedFile->exists()) { throw new \Exception("Could not decrypt message: " . openssl_error_string()); } $decryptedFile->move($srcFile->parent(), $srcFile->name()); } }