/** * Launches an application controller. Returns what the controller returns. * If it is false, a not found error is displayed. * @return boolean */ function Launch() { $Parts = explode("/", $this->Request); $Type = array_shift($Parts); if (!array_key_exists($Type, self::$StaticContentPrefix)) { return false; } $Type = self::$StaticContentPrefix[$Type]; array_unshift($Parts, $Type); $file = jf::root() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $Parts); $FileMan = new DownloadManager(); return $FileMan->Feed($file); }
/** * @fn download * @short Action method that performs the download of a software artifact. * @details For software artifacts that are locally hosted, a DownloadManager is instantiated and the download * is automatically started. For externally hosted artifacts, the client is redirected to the appropriate URL. */ public function download() { if (!empty($_REQUEST['id'])) { $artifact = new SoftwareArtifact(); if ($artifact->find_by_id($_REQUEST['id']) === FALSE) { HTTP::error(404); } $artifact->downloads++; $artifact->save(); if (self::SOFTWARE_SAVE_DOWNLOADS) { // Logs the download $download = new SoftwareDownload(); $download->artifact_id = $_REQUEST['id']; $download->save(); } // Expires the cache of Download Stats // Remember: Download Stats are cached by release_id $this->expire_cached_page(array('action' => 'download_stats', 'id' => $artifact->release_id)); if ($artifact->URL) { $this->redirect_to($artifact->URL); } else { $filename = $artifact->local_file(); if ($filename) { $dl_mgr = new DownloadManager($filename); $dl_mgr->start_download(); } } } $this->redirect_to(array('action' => 'index')); }
/** * Serve some data to the client * @param String $Data * @param String $OutputFilename * @return boolean */ public static function serveData($Data, $OutputFilename) { $Filename = $OutputFilename; header("Content-type: " . DownloadManager::MIME($Filename)); //get the file type. header('Content-disposition: attachment; filename=' . $Filename); //add attachment; here to force download header('Content-length: ' . strlen($Data)); //specify the browser the length of data it must expect. echof($Data); flush(); return true; }
* Private helper method to get the content type for a * file extension (e.g. map mp3 files to audio/mpeg). */ private function getContentType($fileType) { $contentType = 'audio/'; switch (strtolower($fileType)) { case 'mp3': $contentType .= 'mpeg'; break; case 'm4a': $contentType .= 'm4a'; break; case 'ogg': $contentType .= 'ogg'; break; default: die('Unknown file extension. Cannot determine content type.'); break; } return $contentType; } } // Get sample ID from HTTP GET $sampleID = ''; if (!empty($_GET['sid'])) { $sampleID = $_GET['sid']; } // Download file $downloadManager = new DownloadManager(); $downloadManager->fetchSample($sampleID);
/** * To check if we can send some data to the client. */ public function testserveData() { $this->markTestSkipped('Cannot test this in command line context'); $this->assertTrue(DownloadManager::serveData("\n\n\n-->>>Hey this is the test string for function FeedData.<<<--\n\n\n", "myfile.txt")); }