/** * @param SS_HTTPRequest $req * @return HTMLText */ public function download(SS_HTTPRequest $req) { // find the download link $hash = $req->param('Hash'); if (empty($hash)) { $this->httpError(400); } // bad request $link = DownloadLink::get_by_hash($hash); if (!$link || !$link->exists()) { $this->httpError(403); } // access denied // check that the order exists and is valid $order = $link->Order(); if (!$order || !$order->exists() || !$order->DownloadsAvailable()) { $this->httpError(403); } // check the the file still exists $file = $link->File(); if (!$file || !$file->exists()) { $this->httpError(404); } // if the file is under the "small file" tipping point, just pass it through $smallSize = File::ini2bytes(Config::inst()->get('Downloadable', 'small_file_size')); $fileSize = $file->getAbsoluteSize(); if ($fileSize < $smallSize) { $this->addToLog($order->ID, $file); $this->sendFile($file); } else { return $this->initiateOfflineProcessing(array($file), $order->ID); } }