Commit b5c2b014b397140d14e88a93b95fae5f9aba4dce

Authored by Elena.Budnik
1 parent 4a75227e

uploaded_max_filesize conversion to bytes

Showing 1 changed file with 26 additions and 4 deletions   Show diff stats
php/uploadFile.php
@@ -49,7 +49,23 @@ @@ -49,7 +49,23 @@
49 49
50 return $ContentLength; 50 return $ContentLength;
51 } 51 }
  52 +
  53 + function return_bytes($val) {
  54 + $val = trim($val);
  55 + $last = strtolower($val[strlen($val)-1]);
  56 + switch($last) {
  57 + // Le modifieur 'G' est disponible depuis PHP 5.1.0
  58 + case 'g':
  59 + $val *= 1024;
  60 + case 'm':
  61 + $val *= 1024;
  62 + case 'k':
  63 + $val *= 1024;
  64 + }
52 65
  66 + return $val;
  67 + }
  68 +
53 /** 69 /**
54 * Main 70 * Main
55 */ 71 */
@@ -59,8 +75,7 @@ @@ -59,8 +75,7 @@
59 75
60 // error_reporting(E_ERROR | E_WARNING | E_PARSE); 76 // error_reporting(E_ERROR | E_WARNING | E_PARSE);
61 77
62 - if (!isset($_POST['sessionID']))  
63 - { 78 + if (!isset($_POST['sessionID'])) {
64 $response = array( 'success' => false, 'error' => ': Check that uploaded file size is less than '.ini_get('upload_max_filesize')); 79 $response = array( 'success' => false, 'error' => ': Check that uploaded file size is less than '.ini_get('upload_max_filesize'));
65 die(json_encode($response)); 80 die(json_encode($response));
66 } 81 }
@@ -70,8 +85,14 @@ @@ -70,8 +85,14 @@
70 define('USERWSDIR', USERPATH."/".$_POST['sessionID']."/WS/"); 85 define('USERWSDIR', USERPATH."/".$_POST['sessionID']."/WS/");
71 define('USERWORKINGDIR', USERPATH."/".$_POST['sessionID']."/RES/"); 86 define('USERWORKINGDIR', USERPATH."/".$_POST['sessionID']."/RES/");
72 define('ATTACHMENTDIR', DATAPATH."/Feedback/Attach/"); 87 define('ATTACHMENTDIR', DATAPATH."/Feedback/Attach/");
73 - define('maxSize',$_POST['MAX_FILE_SIZE'] < ini_get('upload_max_filesize'));  
74 88
  89 + $upload_max_filesize = return_bytes(ini_get('upload_max_filesize'));
  90 +
  91 + if ($upload_max_filesize > $_POST['MAX_FILE_SIZE'])
  92 + define('maxSize',$_POST['MAX_FILE_SIZE']);
  93 + else
  94 + define('maxSize',$upload_max_filesize); // NEVER !
  95 +
75 if (!is_dir(USERTEMPDIR)) mkdir(USERTEMPDIR.'/', 0755, true); 96 if (!is_dir(USERTEMPDIR)) mkdir(USERTEMPDIR.'/', 0755, true);
76 if (!is_dir(ATTACHMENTDIR)) mkdir(ATTACHMENTDIR.'/', 0755, true); 97 if (!is_dir(ATTACHMENTDIR)) mkdir(ATTACHMENTDIR.'/', 0755, true);
77 98
@@ -157,7 +178,8 @@ @@ -157,7 +178,8 @@
157 178
158 if ($fileSize > maxSize) 179 if ($fileSize > maxSize)
159 { 180 {
160 - $response = array( 'success' => false, 'error' => 'The uploaded file exceeds '.maxSize); 181 + $maxMB = maxSize/1000000;
  182 + $response = array( 'success' => false, 'error' => 'The uploaded file exceeds '.$maxMB.'MB');
161 die(json_encode($response)); 183 die(json_encode($response));
162 } 184 }
163 185