Sfoglia il codice sorgente

Should fix double header bug when downloading a file. See #6807

Julio Montoya 11 anni fa
parent
commit
45d024ca63
2 ha cambiato i file con 7 aggiunte e 17 eliminazioni
  1. 5 4
      main/inc/lib/document.lib.php
  2. 2 13
      main/work/download.php

+ 5 - 4
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

+ 2 - 13
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'];