ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
imgupload.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "../../../../../classes/class.ilIniFile.php";
5 $file = "../../../../../ilias.ini.php";
7 $ini->read();
8 $htdocs=$ini->readVariable("server", "absolute_path") . "/";
9 $weburl=$ini->readVariable("server", "http_path") . "/";
11 
12 // directory where tinymce files are located
13 $iliasMobPath = "data/" . $_GET["client_id"] . "/mobs/";
16 // base url for images
17 $tinyMCE_base_url = "$weburl";
18 
19 $tinyMCE_DOC_url = "$installpath";
20 
21 // image library related config
22 
23 // allowed extentions for uploaded image files
24 $tinyMCE_valid_imgs = array('gif', 'jpg', 'jpeg', 'png');
25 
26 // allow upload in image library
28 
29 // allow delete in image library
31 
32 $_GET["client_id"] = str_replace("..", "", $_GET["client_id"]);
33 
34 $dir = getcwd();
35 chdir("../../../../../");
36 include_once "webservice/soap/include/inc.soap_functions.php";
37 $mobs = ilSoapFunctions::getMobsOfObject($_GET["session_id"]."::".$_GET["client_id"], $_GET["obj_type"].":html", $_GET["obj_id"]);
38 chdir($dir);
39 $preview = "";
41 $request_uri = urldecode(empty($_POST['request_uri'])?(empty($_GET['request_uri'])?'':$_GET['request_uri']):$_POST['request_uri']);
42 $img = isset($_POST['imglist'])? $_POST['imglist'] : '';
44 $errors = array();
45 
46 // upload images
47 $uploadedFile = false;
48 if (isset($_FILES['img_file']['size']) && $_FILES['img_file']['size']>0)
49 {
50  $dir = getcwd();
51  chdir("../../../../../");
52  include_once "webservice/soap/include/inc.soap_functions.php";
53  $safefilename = preg_replace("/[^a-zA-z0-9_\.]/", "", $_FILES["img_file"]["name"]);
54  $media_object = ilSoapFunctions::saveTempFileAsMediaObject($_GET["session_id"]."::".$_GET["client_id"], $safefilename, $_FILES["img_file"]["tmp_name"]);
55  if (file_exists($iliasAbsolutePath.$iliasMobPath."mm_".$media_object->getId() . "/" . $media_object->getTitle()))
56  {
57  // only save usage if the file was uploaded
58  $media_object->_saveUsage($media_object->getId(), $_GET["obj_type"].":html", $_GET["obj_id"]);
59  }
60  chdir($dir);
61 
62  $preview = $iliasHttpPath.$iliasMobPath."mm_".$media_object->getId() . "/" . $media_object->getTitle();
63  $mobs[$media_object->getId()] = $media_object->getId();
64 
65  $uploadedFile = true;
66 }
67 
69 $tpl->loadTemplatefile("tpl.img_upload.html", true, true);
70 
71 $tpl->setVariable("REQUEST_URI", $_GET["request_uri"]);
72 $tpl->setVariable("VALUE_REQUEST_URI", $request_uri);
73 $tpl->setVariable("OBJ_ID", $_GET["obj_id"]);
74 $tpl->setVariable("OBJ_TYPE", $_GET["obj_type"]);
75 $tpl->setVariable("SESSION_ID", $_GET["session_id"]);
76 $tpl->setVariable("CLIENT_ID", $_GET["client_id"]);
77 $tpl->setVariable("VALUE_UPDATE", $_GET["update"]);
78 $tpl->setVariable("ILIAS_INST_PATH", $iliasHttpPath);
79 if ($_GET["update"] == 1)
80 {
81  $tpl->setVariable("INSERT_TYPE", "button");
82  $tpl->setVariable("INSERT_COMMAND", "{#update}");
83  $tpl->touchBlock('src');
84  $tpl->touchBlock('preview');
85 }
86 else
87 {
88  $tpl->setVariable("INSERT_TYPE", "submit");
89  $tpl->setVariable("INSERT_COMMAND", "{#ilimgupload.upload}");
90  $tpl->touchBlock('upload');
91 }
92 
93 $error_messages = "";
94 if(!empty($errors))
95 {
96  $error_messages .= '<span class="error">';
97  foreach ($errors as $err)
98  {
99  $error_messages .= $err . "<br />";
100  }
101  $error_messages .= "</span>";
102 }
103 else if($uploadedFile)
104 {
105  $tpl->setVariable('WIDTH', $_POST['width']);
106  $tpl->setVariable('HEIGHT', $_POST['height']);
107  $tpl->setVariable('SRC', $preview);
108  $tpl->setVariable('ALT', $_POST['alt']);
109  $tpl->touchBlock('adoptimage');
110 }
111 
112 
113 $tpl->setVariable("ERROR_MESSAGES", $error_messages);
114 
115 $tpl->show();
116 
117 function filesize_h($size, $dec = 1)
118 {
119  $sizes = array('byte(s)', 'kb', 'mb', 'gb');
120  $count = count($sizes);
121  $i = 0;
122 
123  while ($size >= 1024 && ($i < $count - 1)) {
124  $size /= 1024;
125  $i++;
126  }
127 
128  return round($size, $dec) . ' ' . $sizes[$i];
129 }
130 ?>