mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +09:00
Allow some file types to be downloaded inline
이미지, 오디오, 비디오, PDF 등 일부 파일을 다운로드하면 다운로드 창을 띄우지 않고 현재 창에 바로 표시할 수 있는 옵션 추가 단, text/html은 보안상 허용하지 않음
This commit is contained in:
parent
b253c8c0b1
commit
2366d61ea4
6 changed files with 64 additions and 8 deletions
|
|
@ -69,6 +69,7 @@ class fileAdminController extends file
|
|||
$config->allow_outlink = Context::get('allow_outlink');
|
||||
$config->allow_outlink_format = Context::get('allow_outlink_format');
|
||||
$config->allow_outlink_site = Context::get('allow_outlink_site');
|
||||
$config->inline_download_format = array_map('utf8_trim', Context::get('inline_download_format'));
|
||||
|
||||
// Check maximum file size
|
||||
if (PHP_INT_SIZE < 8)
|
||||
|
|
|
|||
|
|
@ -405,6 +405,7 @@ class fileController extends file
|
|||
|
||||
$columnList = array('source_filename', 'uploaded_filename', 'file_size');
|
||||
$file_obj = $oFileModel->getFile($file_srl, $columnList);
|
||||
$file_config = $oFileModel->getFileConfig($file_obj->module_srl ?: null);
|
||||
$filesize = $file_obj->file_size;
|
||||
$filename = $file_obj->source_filename;
|
||||
$etag = md5($file_srl . $file_key . $_SERVER['HTTP_USER_AGENT']);
|
||||
|
|
@ -477,16 +478,43 @@ class fileController extends file
|
|||
$range_length = $filesize - $range_start;
|
||||
}
|
||||
|
||||
// Determine download type
|
||||
$download_type = 'attachment';
|
||||
$mime_type = Rhymix\Framework\MIME::getTypeByFilename($filename);
|
||||
if (starts_with('image/', $mime_type) && in_array('image', $file_config->inline_download_format))
|
||||
{
|
||||
$download_type = 'inline';
|
||||
}
|
||||
if (starts_with('audio/', $mime_type) && in_array('audio', $file_config->inline_download_format))
|
||||
{
|
||||
$download_type = 'inline';
|
||||
}
|
||||
if (starts_with('video/', $mime_type) && in_array('video', $file_config->inline_download_format))
|
||||
{
|
||||
$download_type = 'inline';
|
||||
}
|
||||
if (starts_with('text/', $mime_type) && ($mime_type !== 'text/html') && in_array('text', $file_config->inline_download_format))
|
||||
{
|
||||
$download_type = 'inline';
|
||||
}
|
||||
if ($mime_type === 'application/pdf' && in_array('pdf', $file_config->inline_download_format))
|
||||
{
|
||||
$download_type = 'inline';
|
||||
}
|
||||
|
||||
// Clear buffer
|
||||
while(ob_get_level()) ob_end_clean();
|
||||
|
||||
// Set headers
|
||||
header("Cache-Control: private; max-age=3600");
|
||||
header("Pragma: ");
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||
|
||||
header('Content-Disposition: attachment; ' . $filename_param);
|
||||
|
||||
// Set filename headers
|
||||
header('Content-Type: ' . ($download_type === 'inline' ? $mime_type : 'application/octet-stream'));
|
||||
header('Content-Disposition: ' . $download_type . '; ' . $filename_param);
|
||||
|
||||
// Set cache headers
|
||||
header('Cache-Control: private; max-age=3600');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Pragma: ');
|
||||
|
||||
// Set other headers
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: ' . $range_length);
|
||||
header('Accept-Ranges: bytes');
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@ class fileModel extends file
|
|||
$config->allowed_filesize = $file_config->allowed_filesize;
|
||||
$config->allowed_attach_size = $file_config->allowed_attach_size;
|
||||
$config->allowed_filetypes = $file_config->allowed_filetypes;
|
||||
$config->inline_download_format = $file_config->inline_download_format;
|
||||
$config->download_grant = $file_config->download_grant;
|
||||
$config->allow_outlink = $file_config->allow_outlink;
|
||||
$config->allow_outlink_site = $file_config->allow_outlink_site;
|
||||
|
|
@ -207,6 +208,7 @@ class fileModel extends file
|
|||
if(!$config->allowed_filetypes) $config->allowed_filetypes = '*.*';
|
||||
if(!$config->allow_outlink) $config->allow_outlink = 'Y';
|
||||
if(!$config->download_grant) $config->download_grant = array();
|
||||
if(!$config->inline_download_format) $config->inline_download_format = array();
|
||||
|
||||
/*
|
||||
$size = ini_get('upload_max_filesize');
|
||||
|
|
|
|||
|
|
@ -16,6 +16,13 @@ $lang->allow_outlink_format = 'Allowed Formats';
|
|||
$lang->allowed_filesize = 'Maximum File Size';
|
||||
$lang->allowed_attach_size = 'Maximum Attachments';
|
||||
$lang->allowed_filetypes = 'Allowed extentsions';
|
||||
$lang->inline_download_format = 'Open in current window';
|
||||
$lang->inline_download_image = 'Image';
|
||||
$lang->inline_download_audio = 'Audio';
|
||||
$lang->inline_download_video = 'Video';
|
||||
$lang->inline_download_text = 'Text (except HTML)';
|
||||
$lang->inline_download_pdf = 'PDF';
|
||||
$lang->about_inline_download_format = 'Selected types of files will be opened in the current window instead of a download dialog when a user clicks the download link.';
|
||||
$lang->enable_download_group = 'Downloadable Groups';
|
||||
$lang->about_allow_outlink = 'You can block other websites from accessing your download URLs directly.<br />This does not apply to images and other files that can be embedded directly in a document.';
|
||||
$lang->about_allow_outlink_format = 'These file formats will always be allowed.<br />Please use a comma (,) to separate items: e.g. doc, zip, pdf';
|
||||
|
|
|
|||
|
|
@ -16,6 +16,13 @@ $lang->allow_outlink_format = '다운로드 링크 허용 확장자';
|
|||
$lang->allowed_filesize = '파일 크기 제한';
|
||||
$lang->allowed_attach_size = '문서 첨부 제한';
|
||||
$lang->allowed_filetypes = '허용 확장자';
|
||||
$lang->inline_download_format = '다운로드시 현재 창 사용';
|
||||
$lang->inline_download_image = '이미지';
|
||||
$lang->inline_download_audio = '오디오';
|
||||
$lang->inline_download_video = '비디오';
|
||||
$lang->inline_download_text = '텍스트 (HTML 제외)';
|
||||
$lang->inline_download_pdf = 'PDF';
|
||||
$lang->about_inline_download_format = '선택한 종류의 파일은 다운로드 링크를 클릭하더라도 다운로드 창을 열지 않고 현재 창에 표시합니다.';
|
||||
$lang->enable_download_group = '다운로드 가능 그룹';
|
||||
$lang->about_allow_outlink = '다른 사이트에서 파일 다운로드 링크에 직접 접근하는 것을 차단합니다.<br />다운로드 링크를 사용하지 않고 본문에 바로 삽입할 수 있는 이미지 파일 등에는 적용되지 않습니다.';
|
||||
$lang->about_allow_outlink_format = '파일 외부 링크 설정에 상관없이 허용하는 파일 확장자입니다.<br />여러 개 입력시 쉼표(,)을 이용해서 구분해 주세요. 예) doc, zip, pdf';
|
||||
|
|
|
|||
|
|
@ -30,6 +30,17 @@
|
|||
<p class="x_help-block">{$lang->about_allow_outlink_site}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->inline_download_format}</label>
|
||||
<div class="x_controls">
|
||||
<label class="x_inline"><input type="checkbox" name="inline_download_format[]" id="inline_download_format_image" value="image" checked="checked"|cond="in_array('image', $config->inline_download_format)" /> {$lang->inline_download_image}</label>
|
||||
<label class="x_inline"><input type="checkbox" name="inline_download_format[]" id="inline_download_format_audio" value="audio" checked="checked"|cond="in_array('audio', $config->inline_download_format)" /> {$lang->inline_download_audio}</label>
|
||||
<label class="x_inline"><input type="checkbox" name="inline_download_format[]" id="inline_download_format_video" value="video" checked="checked"|cond="in_array('video', $config->inline_download_format)" /> {$lang->inline_download_video}</label>
|
||||
<label class="x_inline"><input type="checkbox" name="inline_download_format[]" id="inline_download_format_text" value="text" checked="checked"|cond="in_array('text', $config->inline_download_format)" /> {$lang->inline_download_text}</label>
|
||||
<label class="x_inline"><input type="checkbox" name="inline_download_format[]" id="inline_download_format_pdf" value="pdf" checked="checked"|cond="in_array('pdf', $config->inline_download_format)" /> {$lang->inline_download_pdf}</label>
|
||||
<p class="x_help-block">{$lang->about_inline_download_format}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label for="allowed_filesize" class="x_control-label">{$lang->allowed_filesize}</label>
|
||||
<div class="x_controls">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue