ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilFileUploadUtil.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
23 public static function isUploadAllowed($a_ref_id, $a_type = "")
24 {
25 global $DIC;
26 $objDefinition = $DIC['objDefinition'];
27 $ilAccess = $DIC['ilAccess'];
28
29 if (self::isUploadSupported()) {
30 include_once("./Services/FileUpload/classes/class.ilFileUploadSettings.php");
31
32 // repository upload enabled?
35 if ($a_type == "") {
36 $a_type = ilObject::_lookupType($a_ref_id, true);
37 }
38
39 if ($objDefinition->isContainer($a_type)) {
40 return $ilAccess->checkAccess("create_file", "", $a_ref_id, "file");
41 }
42 }
43 }
44
45 return false;
46 }
47
53 public static function isUploadSupported()
54 {
55 global $DIC;
56 $ilCtrl = $DIC['ilCtrl'];
57
58 // right now, only the repository is supported
59 if (strtolower($_GET["baseClass"]) == "ilrepositorygui") {
60 $cmd = $ilCtrl->getCmd();
61 if ($cmd == "" || $cmd == "view" || $cmd == "render") {
62 return true;
63 }
64 }
65
66 return false;
67 }
68
74 public static function getMaxFileSize()
75 {
76 // get the value for the maximal uploadable filesize from the php.ini (if available)
77 $umf = ini_get("upload_max_filesize");
78 // get the value for the maximal post data from the php.ini (if available)
79 $pms = ini_get("post_max_size");
80
81 //convert from short-string representation to "real" bytes
82 $multiplier_a = array("K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024);
83
84 $umf_parts = preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
85 $pms_parts = preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
86
87 if (count($umf_parts) == 2) {
88 $umf = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
89 }
90 if (count($pms_parts) == 2) {
91 $pms = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
92 }
93
94 // use the smaller one as limit
95 $max_filesize = min($umf, $pms);
96
97 if (!$max_filesize) {
98 $max_filesize = max($umf, $pms);
99 }
100
101 return $max_filesize;
102 }
103
109 public static function getMaxFileSizeString()
110 {
111 $max_filesize = self::getMaxFileSize();
112
113 // format for display in mega-bytes
114 return sprintf("%.1f MB", $max_filesize / 1024 / 1024);
115 }
116}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static isRepositoryDragAndDropUploadEnabled()
Gets whether drag and drop file upload in the repository is enabled.
static isDragAndDropUploadEnabled()
Gets whether drag and drop file upload is enabled.
static getMaxFileSize()
Gets the maximum upload file size allowed in bytes.
static isUploadSupported()
Determines whether file upload is supported at the current location.
static isUploadAllowed($a_ref_id, $a_type="")
Determines whether files can be uploaded to the object with the specified reference id.
static getMaxFileSizeString()
Gets the maximum upload file size allowed as string (like '14.2 MB').
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilCtrl
Definition: ilias.php:18
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46