Skip to content

Commit

Permalink
Update FileUploader.php
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Dec 22, 2024
1 parent d416430 commit 247c967
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion webfiori/file/FileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,27 @@ private function getFileArr($fileOrFiles,$replaceIfExist, ?string $idx): array {

return $fileInfoArr;
}
/**
* Returns the value of the directive 'upload_max_filesize' in KB.
*
* @return int
*/
public static function getMaxFileSize() : int {
$val = ini_get('upload_max_filesize');
$lastChar = strtoupper($val[strlen($val) - 1]);

Check warning on line 617 in webfiori/file/FileUploader.php

View check run for this annotation

Codecov / codecov/patch

webfiori/file/FileUploader.php#L615-L617

Added lines #L615 - L617 were not covered by tests

switch ($lastChar) {
case 'M' : {
return intval($val) * 1000;
} case 'K' : {
return intval($val);
} case 'G' : {
return intval($val) * 1000000;

Check warning on line 625 in webfiori/file/FileUploader.php

View check run for this annotation

Codecov / codecov/patch

webfiori/file/FileUploader.php#L619-L625

Added lines #L619 - L625 were not covered by tests
} default : {
return intval($val) / 1000;

Check warning on line 627 in webfiori/file/FileUploader.php

View check run for this annotation

Codecov / codecov/patch

webfiori/file/FileUploader.php#L627

Added line #L627 was not covered by tests
}
}
}
/**
* Checks if PHP upload code is error or not.
*
Expand All @@ -625,7 +646,7 @@ private function isError(int $code): bool {
return false;
}
case UPLOAD_ERR_INI_SIZE:{
$this->uploadStatusMessage = 'File Size is Larger Than '.(intval(ini_get('upload_max_filesize')) / 1000).'KB. Found in php.ini.';
$this->uploadStatusMessage = 'File Size is Larger Than '.(self::getMaxFileSize()).'KB. Found in php.ini.';

Check warning on line 649 in webfiori/file/FileUploader.php

View check run for this annotation

Codecov / codecov/patch

webfiori/file/FileUploader.php#L649

Added line #L649 was not covered by tests
break;
}
case UPLOAD_ERR_PARTIAL:{
Expand Down

0 comments on commit 247c967

Please sign in to comment.