| Conditions | 30 |
| Paths | 1516 |
| Total Lines | 132 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 197 | function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '') |
||
| 198 | { |
||
| 199 | if (!isset($_FILES)) { |
||
| 200 | global $_FILES; |
||
| 201 | } |
||
| 202 | $sErrorNumber = '0' ; |
||
| 203 | $sFileName = '' ; |
||
| 204 | |||
| 205 | if ( isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name']) |
||
| 206 | // This is for the QuickUpload tab box |
||
| 207 | or (isset($_FILES['upload']) && !is_null($_FILES['upload']['tmp_name']))) |
||
| 208 | { |
||
| 209 | global $Config ; |
||
| 210 | |||
| 211 | $oFile = isset($_FILES['NewFile']) ? $_FILES['NewFile'] : $_FILES['upload']; |
||
| 212 | |||
| 213 | // Map the virtual path to the local server path. |
||
| 214 | $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand); |
||
| 215 | |||
| 216 | // Get the uploaded file name. |
||
| 217 | $sFileName = $oFile['name'] ; |
||
| 218 | $sFileName = SanitizeFileName($sFileName); |
||
| 219 | |||
| 220 | $sOriginalFileName = $sFileName ; |
||
| 221 | |||
| 222 | // Get the extension. |
||
| 223 | $sExtension = substr($sFileName, (strrpos($sFileName, '.') + 1)); |
||
| 224 | $sExtension = strtolower($sExtension); |
||
| 225 | |||
| 226 | if ( isset($Config['SecureImageUploads']) ) |
||
| 227 | { |
||
| 228 | if ( ( $isImageValid = IsImageValid($oFile['tmp_name'], $sExtension) ) === false ) |
||
| 229 | { |
||
| 230 | $sErrorNumber = '202' ; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | if ( isset($Config['HtmlExtensions']) ) |
||
| 235 | { |
||
| 236 | if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && |
||
| 237 | ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) |
||
| 238 | { |
||
| 239 | $sErrorNumber = '202' ; |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | // Check if it is an allowed extension. |
||
| 244 | if ( !$sErrorNumber && IsAllowedExt($sExtension, $resourceType) ) |
||
| 245 | { |
||
| 246 | $iCounter = 0 ; |
||
| 247 | |||
| 248 | while ( true ) |
||
| 249 | { |
||
| 250 | $sFilePath = $sServerDir . $sFileName ; |
||
| 251 | |||
| 252 | if ( is_file($sFilePath) ) |
||
| 253 | { |
||
| 254 | $iCounter++ ; |
||
| 255 | $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension ; |
||
| 256 | $sErrorNumber = '201' ; |
||
| 257 | } |
||
| 258 | else |
||
| 259 | { |
||
| 260 | move_uploaded_file($oFile['tmp_name'], $sFilePath); |
||
| 261 | |||
| 262 | if ( is_file($sFilePath) ) |
||
| 263 | { |
||
| 264 | if ( isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload'] ) |
||
| 265 | { |
||
| 266 | break ; |
||
| 267 | } |
||
| 268 | |||
| 269 | $permissions = '0777'; |
||
| 270 | if ( isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload'] ) |
||
| 271 | { |
||
| 272 | $permissions = (string) $Config['ChmodOnUpload'] ; |
||
| 273 | } |
||
| 274 | $permissionsdec = octdec($permissions); |
||
| 275 | dol_syslog("commands.php permission = ".$permissions." ".$permissionsdec." ".decoct($permissionsdec)); |
||
| 276 | $oldumask = umask(0); |
||
| 277 | chmod($sFilePath, $permissionsdec); |
||
| 278 | umask($oldumask); |
||
| 279 | } |
||
| 280 | |||
| 281 | break ; |
||
| 282 | } |
||
| 283 | } |
||
| 284 | |||
| 285 | if ( file_exists($sFilePath) ) |
||
|
|
|||
| 286 | { |
||
| 287 | //previous checks failed, try once again |
||
| 288 | if ( isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false ) |
||
| 289 | { |
||
| 290 | @unlink($sFilePath); |
||
|
1 ignored issue
–
show
|
|||
| 291 | $sErrorNumber = '202' ; |
||
| 292 | } |
||
| 293 | elseif ( isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true ) |
||
| 294 | { |
||
| 295 | @unlink($sFilePath); |
||
| 296 | $sErrorNumber = '202' ; |
||
| 297 | } |
||
| 298 | } |
||
| 299 | } |
||
| 300 | else |
||
| 301 | $sErrorNumber = '202' ; |
||
| 302 | } |
||
| 303 | else |
||
| 304 | $sErrorNumber = '202' ; |
||
| 305 | |||
| 306 | |||
| 307 | $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder); |
||
| 308 | $sFileUrl = CombinePaths($sFileUrl, $sFileName); |
||
| 309 | |||
| 310 | |||
| 311 | // @CHANGE |
||
| 312 | //SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ); |
||
| 313 | if($CKEcallback == '') |
||
| 314 | { |
||
| 315 | // this line already exists so wrap the if block around it |
||
| 316 | SendUploadResults($sErrorNumber, $sFileUrl, $sFileName); |
||
| 317 | } |
||
| 318 | else |
||
| 319 | { |
||
| 320 | //issue the CKEditor Callback |
||
| 321 | SendCKEditorResults( |
||
| 322 | $CKEcallback, |
||
| 323 | $sFileUrl, |
||
| 324 | ($sErrorNumber != 0 ? 'Error '. $sErrorNumber. ' upload failed.' : 'Upload Successful') |
||
| 325 | ); |
||
| 326 | } |
||
| 327 | |||
| 328 | exit; |
||
|
1 ignored issue
–
show
|
|||
| 329 | } |
||
| 330 |