Created
April 7, 2016 17:09
-
-
Save flayder/587da3330d75c78c5f833ff4adf7818b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
include($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/include/prolog_before.php'); | |
CModule::IncludeModule('iblock'); | |
$elID = trim($_REQUEST['id']); | |
$arFile = false; | |
$action = 'download'; | |
if ($elID) { | |
$dbElement = CIBlockElement::GetList( | |
array(), | |
array("ID" => $elID), | |
false, | |
array("nTopCount" => "1"), | |
array("ID", "CODE", "PROPERTY_FILE") | |
); | |
if ($dbElement->SelectedRowsCount()) { | |
while ($arElement = $dbElement->Fetch()) { | |
$tFile = CFile::GetFileArray($arElement['PROPERTY_FILE_VALUE']); | |
$tFileName = explode('.', $tFile['FILE_NAME']); | |
if ($arElement['CODE']) { | |
$fileName = $arElement['CODE'] . '.' . array_pop($tFileName); | |
} else { | |
$fileName = $arElement['ID'] . '.' . array_pop($tFileName); | |
} | |
$arFile = array( | |
'NAME' => $fileName, | |
'CONTENT_TYPE' => $tFile['CONTENT_TYPE'], | |
'CONTENT' => file_get_contents($_SERVER['DOCUMENT_ROOT'] . $tFile['SRC']), | |
'ACTION' => ($action=='download')?'attachment':'inline' | |
); | |
} | |
} | |
} | |
if ($arFile) { | |
ob_start(); | |
header('Content-type: ' . $arFile['CONTENT_TYPE']); | |
header('Content-disposition: ' . $arFile['ACTION'] . '; filename = ' . $arFile['NAME']); | |
echo $arFile['CONTENT']; | |
ob_end_flush(); | |
} else { | |
$APPLICATION->RestartBuffer(); | |
include $_SERVER['DOCUMENT_ROOT']."/bitrix/templates/".SITE_TEMPLATE_ID."/header.php"; | |
require ($_SERVER["DOCUMENT_ROOT"]."/404.php"); | |
include $_SERVER['DOCUMENT_ROOT']."/bitrix/templates/".SITE_TEMPLATE_ID."/footer.php"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment