Skip to content

Commit

Permalink
Fixed issue #12164: Bad header when download file in Response browsing
Browse files Browse the repository at this point in the history
Dev: little fix for public part in case of broken file
Dev: tested with a pdf renames as png
  • Loading branch information
Shnoulle committed Feb 28, 2017
1 parent 59f5195 commit 982e639
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion application/controllers/UploaderController.php
Expand Up @@ -61,7 +61,11 @@ function run($actionID)
}
if(is_file($sFileDir.$sFileGetContent))// Validate file before else 500 error by getMimeType
{
header('Content-Type: '. CFileHelper::getMimeType($sFileDir.$sFileGetContent));
$mimeType=CFileHelper::getMimeType($sFileDir.$sFileGetContent, null, false);
if(is_null($mimeType)){
$mimeType="application/octet-stream"; // Can not really get content if not image
}
header('Content-Type: '. $mimeType);
readfile($sFileDir.$sFileGetContent);
Yii::app()->end();
}
Expand Down
10 changes: 7 additions & 3 deletions application/controllers/admin/responses.php
Expand Up @@ -270,7 +270,7 @@ public function view($iSurveyID, $iId, $sBrowseLang = '')
$index = $fnames[$i]['index'];
$metadata = $fnames[$i]['metadata'];
$phparray = json_decode_ls($iIdrow[$fnames[$i][0]]);

if (isset($phparray[$index]))
{
switch ($metadata)
Expand Down Expand Up @@ -551,7 +551,7 @@ public function actionDownloadfile($iSurveyId, $iResponseId, $iQID, $iIndex)
$iIndex=(int)$iIndex;
$iResponseId=(int)$iResponseId;
$iQID=(int)$iQID;

if(Permission::model()->hasSurveyPermission($iSurveyId,'responses','read'))
{
$oResponse = Response::model($iSurveyId)->findByPk($iResponseId);
Expand All @@ -562,9 +562,13 @@ public function actionDownloadfile($iSurveyId, $iResponseId, $iQID, $iIndex)
$sFileRealName = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyId . "/files/" . $aFile['filename'];
if (file_exists($sFileRealName))
{
$mimeType=CFileHelper::getMimeType($sFileRealName, null, false);
if(is_null($mimeType)){
$mimeType="application/octet-stream";
}
@ob_clean();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');// Find the real type ?
header('Content-Type: '.$mimeType);
header('Content-Disposition: attachment; filename="' . rawurldecode($aFile['name']) . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
Expand Down

0 comments on commit 982e639

Please sign in to comment.