public function _Download($Sender, $Args) { try { // Create the zip file. $Path = $this->CreateZip(); // Serve the zip file. Gdn_FileSystem::ServeFile($Path, basename($Path), 'application/zip'); } catch (Exception $Ex) { $this->Form->AddError($Ex); $this->_Settings($Sender, $Args); } }
/** * DiscussionController_Download_Create function. * * @access public * @param mixed $Sender * @return void */ public function DiscussionController_Download_Create($Sender) { if (!$this->IsEnabled()) { return; } if (!$this->CanDownload) { throw new PermissionException("File could not be streamed: Access is denied"); } list($MediaID) = $Sender->RequestArgs; $Media = $this->MediaModel()->GetID($MediaID); if (!$Media) { return; } $Filename = Gdn::Request()->Filename(); if (!$Filename) { $Filename = $Media->Name; } $DownloadPath = CombinePaths(array(MediaModel::PathUploads(), GetValue('Path', $Media))); if (in_array(strtolower(pathinfo($Filename, PATHINFO_EXTENSION)), array('bmp', 'gif', 'jpg', 'jpeg', 'png'))) { $ServeMode = 'inline'; } else { $ServeMode = 'attachment'; } $this->EventArguments['Media'] = $Media; $this->FireEvent('BeforeDownload'); return Gdn_FileSystem::ServeFile($DownloadPath, $Filename, '', $ServeMode); throw new Exception('File could not be streamed: missing file (' . $DownloadPath . ').'); exit; }