ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 $objDefinition, $ilAccess;
26 
27  if (self::isUploadSupported())
28  {
29  include_once("./Services/FileUpload/classes/class.ilFileUploadSettings.php");
30 
31  // repository upload enabled?
34  {
35  if ($a_type == "")
36  $a_type = ilObject::_lookupType($a_ref_id, true);
37 
38  if ($objDefinition->isContainer($a_type))
39  return $ilAccess->checkAccess("create_file", "", $a_ref_id, "file");
40  }
41  }
42 
43  return false;
44  }
45 
51  public static function isUploadSupported()
52  {
53  global $ilCtrl;
54 
55  // right now, only the repository is supported
56  if (strtolower($_GET["baseClass"]) == "ilrepositorygui")
57  {
58  $cmd = $ilCtrl->getCmd();
59  if ($cmd == "" || $cmd == "view" || $cmd == "render")
60  return true;
61  }
62 
63  return false;
64  }
65 
71  public static function getMaxFileSize()
72  {
73  // get the value for the maximal uploadable filesize from the php.ini (if available)
74  $umf = ini_get("upload_max_filesize");
75  // get the value for the maximal post data from the php.ini (if available)
76  $pms = ini_get("post_max_size");
77 
78  //convert from short-string representation to "real" bytes
79  $multiplier_a=array("K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024);
80 
81  $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
82  $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
83 
84  if (count($umf_parts) == 2) {
85  $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]];
86  }
87  if (count($pms_parts) == 2) {
88  $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]];
89  }
90 
91  // use the smaller one as limit
92  $max_filesize = min($umf, $pms);
93 
94  if (!$max_filesize)
95  $max_filesize=max($umf, $pms);
96 
97  return $max_filesize;
98  }
99 
105  public static function getMaxFileSizeString()
106  {
107  $max_filesize = self::getMaxFileSize();
108 
109  // format for display in mega-bytes
110  return sprintf("%.1f MB", $max_filesize / 1024 / 1024);
111  }
112 }
113 ?>