Browse Source

Fix php warning + add "ext-fileinfo" needed in order to use mime_content_type()

Julio Montoya 6 years ago
parent
commit
1ca163b39f
2 changed files with 7 additions and 7 deletions
  1. 1 0
      composer.json
  2. 6 7
      main/work/work.lib.php

+ 1 - 0
composer.json

@@ -44,6 +44,7 @@
         "ext-mbstring": "*",
         "ext-libxml": "*",
         "ext-dom": "*",
+        "ext-fileinfo": "*",
         "twig/twig": "1.*",
         "twig/extensions": "~1.0",
         "doctrine/orm": "~2.4",

+ 6 - 7
main/work/work.lib.php

@@ -137,9 +137,11 @@ function get_work_data_by_id($id, $courseId = 0, $sessionId = 0)
         $work['show_url'] = $webCodePath.'work/show_file.php?id='.$work['id'].'&'.api_get_cidreq();
         $work['show_content'] = '';
         if ($work['contains_file']) {
-            $fileType = mime_content_type(
-                api_get_path(SYS_COURSE_PATH).$course->getDirectory().'/'.$work['url']
-            );
+            $fileType = '';
+            $file = api_get_path(SYS_COURSE_PATH).$course->getDirectory().'/'.$work['url'];
+            if (file_exists($file)) {
+                $fileType = mime_content_type($file);
+            }
 
             if (in_array($fileType, ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'])) {
                 $work['show_content'] = Display::img($work['show_url'], $work['title']);
@@ -153,10 +155,7 @@ function get_work_data_by_id($id, $courseId = 0, $sessionId = 0)
         }
 
         $fieldValue = new ExtraFieldValue('work');
-        $work['extra'] = $fieldValue->getAllValuesForAnItem(
-            $id,
-            true
-        );
+        $work['extra'] = $fieldValue->getAllValuesForAnItem($id, true);
     }
 
     return $work;