Skip to content

Commit

Permalink
Merge pull request #179
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
leonardosahon authored Oct 17, 2024
2 parents e959fae + 3cb9dd8 commit a1fdbd5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Core/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function always_log() : void

public static function log(string $message, $exception = null) : void
{
self::throw_exception($message, "ManualLog", kill: false, exception: $exception);
self::throw_exception($message, "ManualLog", kill: false, exception: $exception, throw_500: false);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Libs/FileUpload/Enums/FileUploadErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

enum FileUploadErrors
{
case NO_POST_NAME;
case EXCEEDS_FILE_LIMIT;
case FILE_NOT_SET;
case TMP_FILE_EMPTY;
Expand Down
33 changes: 21 additions & 12 deletions src/Libs/FileUpload/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,24 @@ public function __construct(
extension_list: $opts['extension_list'] ?? null,
);

if($req)
if($req) {
if($req['error_type'] == FileUploadErrors::NO_POST_NAME)
return $this->response = null;

return $this->response = $req;
}

if( !$req ) {
$mime = mime_content_type($_FILES[$opts['post_name']]['tmp_name']);

if(str_starts_with($mime, "image/"))
$this->upload_type = FileUploadType::IMG;
$mime = mime_content_type($_FILES[$opts['post_name']]['tmp_name']);

elseif(str_starts_with($mime, "video/"))
$this->upload_type = FileUploadType::VIDEO;
if(str_starts_with($mime, "image/"))
$this->upload_type = FileUploadType::IMG;

else
$this->upload_type = FileUploadType::DOC;
}
elseif(str_starts_with($mime, "video/"))
$this->upload_type = FileUploadType::VIDEO;

else
$this->upload_type = FileUploadType::DOC;

if($this->upload_type == FileUploadType::IMG)
$this->response = $this->image_upload($opts);
Expand Down Expand Up @@ -193,15 +196,21 @@ private function upload_response(
* @throws \Exception
*/
private function check_all_requirements(
?string $post_name,
?string $post_name,
?int $file_limit = null,
FileUploadExtension|null|string $extension = null,
?array $custom_mime = null,
?array $extension_list = null,
) : ?array
{
if(!$post_name)
return null;
return $this->upload_response (
false,
[
"error" => "No post_name received",
"error_type" => FileUploadErrors::NO_POST_NAME,
]
);

if(!isset($_FILES[$post_name]))
return $this->upload_response (
Expand Down

0 comments on commit a1fdbd5

Please sign in to comment.