Commit 554fbb669da32b59c384b473a49e6c9e5f491e12

Authored by sergem
1 parent fc4d488b

Added webservice calls to check for maximum file size on server

Committed by: Serge Meunier
webservice/clienttools/comms.php
... ... @@ -74,7 +74,9 @@ $noAuthRequests=array(
74 74 //'auth.japiLogin',
75 75 'kt.get_all_client_policies',
76 76 'kt.get_languages',
77   - 'kt.switchlang'
  77 + 'kt.switchlang',
  78 + 'kt.get_max_fileupload_size',
  79 + 'kt.get_all_explorer_policies'
78 80 );
79 81  
80 82 if (KTPluginUtil::pluginIsActive('ktdms.wintools')) {
... ...
webservice/clienttools/services/0.9/kt.php
... ... @@ -1281,5 +1281,45 @@ Fatal error: Cannot unset string offsets in on line 981
1281 1281  
1282 1282 }
1283 1283 }
  1284 +
  1285 + private function convert_size_to_num($size)
  1286 + {
  1287 + //This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case)
  1288 + $l = substr($size, -1);
  1289 + $ret = substr($size, 0, -1);
  1290 + switch(strtoupper($l)){
  1291 + case 'P':
  1292 + $ret *= 1024;
  1293 + case 'T':
  1294 + $ret *= 1024;
  1295 + case 'G':
  1296 + $ret *= 1024;
  1297 + case 'M':
  1298 + $ret *= 1024;
  1299 + case 'K':
  1300 + $ret *= 1024;
  1301 + break;
  1302 + }
  1303 + return $ret;
  1304 + }
  1305 +
  1306 + /*
  1307 + * Determing the maximum size a file can be to upload
  1308 + */
  1309 + function get_max_fileupload_size()
  1310 + {
  1311 + $post_max_size = $this->convert_size_to_num(ini_get('post_max_size'));
  1312 + $upload_max_filesize = $this->convert_size_to_num(ini_get('upload_max_filesize'));
  1313 +
  1314 + if ($upload_max_filesize < 0) {
  1315 + $max_upload_size = $post_max_size;
  1316 + } else {
  1317 + $max_upload_size = min($post_max_size, $upload_max_filesize);
  1318 + }
  1319 + $this->setResponse ( array ('status_code' => 0, 'maxsize' => $max_upload_size ) );
  1320 + return true;
  1321 + }
1284 1322 }
  1323 +
  1324 +
1285 1325 ?>
1286 1326 \ No newline at end of file
... ...