request->getParam('tk'); $forceDownload = Craft::$app->request->getParam('download') == 'true'; if($encryptedString){ $decryptedString = Craft::$app->security->unmaskToken($encryptedString); $obj = json_decode($decryptedString); if($obj->timestamp !== null && $obj->assetId !== null){ $currentTimestamp = time(); if($obj->timestamp > $currentTimestamp){ $storagePath = Craft::getAlias('@root/protected-files'); $asset = Asset::find()->id($obj->assetId)->one(); if($asset){ return Craft::$app->response->sendFile($storagePath . '/' . $asset->filename, $asset->filename, ['inline' => false]); } } else { return 'The current url validity has expired'; } } } return 'The current url is not valid.'; } }