本文整理汇总了PHP中WebPage::SetContentDisposition方法的典型用法代码示例。如果您正苦于以下问题:PHP WebPage::SetContentDisposition方法的具体用法?PHP WebPage::SetContentDisposition怎么用?PHP WebPage::SetContentDisposition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebPage
的用法示例。
在下文中一共展示了WebPage::SetContentDisposition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DownloadDocument
/**
* Downloads a document to the browser, either as 'inline' or 'attachment'
*
* @param WebPage $oPage The web page for the output
* @param string $sClass Class name of the object
* @param mixed $id Identifier of the object
* @param string $sAttCode Name of the attribute containing the document to download
* @param string $sContentDisposition Either 'inline' or 'attachment'
* @return none
*/
function DownloadDocument(WebPage $oPage, $sClass, $id, $sAttCode, $sContentDisposition = 'attachment')
{
try {
$oObj = MetaModel::GetObject($sClass, $id, false, false);
if (!is_object($oObj)) {
throw new Exception("Invalid id ({$id}) for class '{$sClass}' - the object does not exist or you are not allowed to view it");
}
$oDocument = $oObj->Get($sAttCode);
if (is_object($oDocument)) {
$oPage->TrashUnexpectedOutput();
$oPage->SetContentType($oDocument->GetMimeType());
$oPage->SetContentDisposition($sContentDisposition, $oDocument->GetFileName());
$oPage->add($oDocument->GetData());
}
} catch (Exception $e) {
$oPage->p($e->getMessage());
}
}
示例2: AsyncAction
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
{
$oParameters = new PHPParameters();
// For security reasons: add the extension now so that this action can be used to read *only* .zip files from the disk...
$sBackupFile = $aParameters['backup'] . '.zip';
if (file_exists($sBackupFile)) {
// Make sure there is NO output at all before our content, otherwise the document will be corrupted
$sPreviousContent = ob_get_clean();
$oPage->SetContentType('application/zip');
$oPage->SetContentDisposition('attachment', basename($sBackupFile));
$oPage->add(file_get_contents($sBackupFile));
}
}