From 45d024ca633519a6b0fec0bd8ce39dcd73b1cc60 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 4 Nov 2013 13:07:07 +0100 Subject: [PATCH] Should fix double header bug when downloading a file. See #6807 --- main/inc/lib/document.lib.php | 9 +++++---- main/work/download.php | 15 ++------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 3b47fdeeeb..18802aa192 100644 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -317,12 +317,13 @@ class DocumentManager $filename = ($name == '') ? basename($full_file_name) : replace_dangerous_char($name); $len = filesize($full_file_name); + // Fixing error when file name contains a "," + $filename = str_replace(',', '', $filename); if ($forced) { - //force the browser to save the file instead of opening it + // Force the browser to save the file instead of opening it header('Content-type: application/octet-stream'); - //header('Content-Type: application/force-download'); header('Content-length: ' . $len); if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) { header('Content-Disposition: filename= ' . $filename); @@ -337,8 +338,8 @@ class DocumentManager header('Content-Description: ' . $filename); header('Content-transfer-encoding: binary'); - $fp = fopen($full_file_name, 'r'); - fpassthru($fp); + $res = fopen($full_file_name, 'r'); + fpassthru($res); return true; } else { //no forced download, just let the browser decide what to do according to the mimetype diff --git a/main/work/download.php b/main/work/download.php index fb7805dc7e..95bfac5341 100644 --- a/main/work/download.php +++ b/main/work/download.php @@ -9,21 +9,13 @@ * * @package chamilo.work */ - -session_cache_limiter('public'); require_once '../inc/global.inc.php'; require_once 'work.lib.php'; $current_course_tool = TOOL_STUDENTPUBLICATION; - $this_section = SECTION_COURSES; -// IMPORTANT to avoid caching of documents -header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); -header('Cache-Control: public'); -header('Pragma: no-cache'); - -//protection +// Course protection api_protect_course_script(true); $id = intval($_GET['id']); @@ -81,10 +73,7 @@ if (!empty($course_info['real_id'])) { $is_editor = api_is_allowed_to_edit(true, true, true); $student_is_owner_of_work = user_is_author($row['id'], $row['user_id']); - if ($is_editor - //|| (!$doc_visible_for_all && $work_is_visible && $student_is_owner_of_work) - || ($student_is_owner_of_work) - || ($doc_visible_for_all && $work_is_visible)) { + if ($is_editor || ($student_is_owner_of_work) || ($doc_visible_for_all && $work_is_visible)) { $title = $row['title'];