Skip to content

Commit

Permalink
Add File::getMaxUploadSize()
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers committed Nov 5, 2024
1 parent 5db08af commit 8675a20
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ public function sizeToBytes(string $size): string
throw new InvalidArgumentException("Invalid size format '$size'");
}

/**
* Retrieves the maximum file upload size allowed by the server configuration.
* Compares `upload_max_filesize` and `post_max_size` and returns the smaller value.
*
* @return string The maximum upload size in bytes as a string.
*/
public function getMaxUploadSize(): string
{
// Get `upload_max_filesize` and `post_max_size` from PHP configuration
$uploadMaxSize = ini_get('upload_max_filesize');
$postMaxSize = ini_get('post_max_size');

// Convert both values to bytes using sizeToBytes
$uploadMaxSizeBytes = $this->sizeToBytes($uploadMaxSize);
$postMaxSizeBytes = $this->sizeToBytes($postMaxSize);

// Compare as floats and return the smaller value as a string
return (float) $uploadMaxSizeBytes > (float) $postMaxSizeBytes ? $postMaxSizeBytes : $uploadMaxSizeBytes;
}

/**
* Returns a public file path from an absolute path.
*
Expand Down

0 comments on commit 8675a20

Please sign in to comment.