From c0ed443042d1ee0277cfa779455837f68e0eb95a Mon Sep 17 00:00:00 2001 From: Laurent Giovannoni <laurent.giovannoni@maarch.org> Date: Tue, 9 Aug 2011 16:37:21 +0000 Subject: [PATCH] evo : control mime type on store resource --- .../trunk/core/class/docservers_controler.php | 1 + core/trunk/core/docservers_tools.php | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/core/trunk/core/class/docservers_controler.php b/core/trunk/core/class/docservers_controler.php index dafe037fa8b..b10a16b2d8b 100644 --- a/core/trunk/core/class/docservers_controler.php +++ b/core/trunk/core/class/docservers_controler.php @@ -33,6 +33,7 @@ //Loads the required class try { + require_once 'core/class/class_request.php'; require_once 'core/class/docservers.php'; require_once 'core/docservers_tools.php'; require_once 'core/core_tables.php'; diff --git a/core/trunk/core/docservers_tools.php b/core/trunk/core/docservers_tools.php index 0d5fc0d5f87..724e67f61c4 100644 --- a/core/trunk/core/docservers_tools.php +++ b/core/trunk/core/docservers_tools.php @@ -531,3 +531,54 @@ function Ds_isCompleteFile($file, $delay=500, $pointer=0) return Ds_isCompleteFile($file, $delay, $currentPos); } } + +/** + * Check the mime type of a file with the extension config file +* Return array with the status of the check and the mime type of the file +* @param string $filePath +* @param array +*/ +function Ds_isFileTypeAllowed($filePath) +{ + $mimeType = Ds_getMimeType( + $filePath + ); + if (file_exists($_SESSION['config']['corepath'] . 'custom' + . DIRECTORY_SEPARATOR.$_SESSION['custom_override_id'] + . DIRECTORY_SEPARATOR + . 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] + . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR + . 'extensions.xml') + ) { + $path = $_SESSION['config']['corepath'] . 'custom' + . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] + . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR + . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'xml' + . DIRECTORY_SEPARATOR . 'extensions.xml'; + } else { + $path = 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] + . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'extensions.xml'; + } + $xmlconfig = simplexml_load_file($path); + $ext_list = array(); + $i = 0; + foreach($xmlconfig->FORMAT as $FORMAT) { + $ext_list[$i] = array( + 'name' => (string) $FORMAT->name, + 'mime' => (string) $FORMAT->mime + ); + $i++; + } + $type_state = false; + for($i=0;$i<count($ext_list);$i++) { + if($ext_list[$i]['mime'] == $mimeType) { + $type_state = true; + break; + } + } + $arrayReturn = array( + 'status' => $type_state, + 'mime_type' => $mimeType, + ); + return $arrayReturn; +} -- GitLab