Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Dec 1, 2024
1 parent 6265f0e commit b3ce6cb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
42 changes: 27 additions & 15 deletions objects/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,36 @@ function file_get_intbound_contents($url, $bindto_addr_family)
return file_get_contents($url, false, $stream_context);
}

// Returns a file size limit in bytes based on the PHP upload_max_filesize
// and post_max_size
function file_upload_max_size()
{
static $max_size = -1;
function file_upload_max_size() {
// Retrieve the values from php.ini
$uploadMaxFileSize = ini_get('upload_max_filesize');
$postMaxSize = ini_get('post_max_size');

if ($max_size < 0) {
// Start with post_max_size.
$max_size = parse_size(ini_get('post_max_size'));
// Convert both values to bytes
$uploadMaxFileSizeBytes = convertToBytes($uploadMaxFileSize);
$postMaxSizeBytes = convertToBytes($postMaxSize);

// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$upload_max = parse_size(ini_get('upload_max_filesize'));
if ($upload_max > 0 && $upload_max < $max_size) {
$max_size = $upload_max;
}
// Return the smaller of the two values
return min($uploadMaxFileSizeBytes, $postMaxSizeBytes);
}

function convertToBytes($value) {
$unit = strtoupper(substr($value, -1));
$bytes = (int)$value;

switch ($unit) {
case 'G':
$bytes *= 1024 ** 3;
break;
case 'M':
$bytes *= 1024 ** 2;
break;
case 'K':
$bytes *= 1024;
break;
}
return $max_size;

return $bytes;
}

function parse_size($size)
Expand Down
2 changes: 0 additions & 2 deletions objects/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def add_user_agent():
("Accept-Language", "en-US,en;q=0.9"),
("Accept", "*/*"),
("Connection", "keep-alive"),
("X-Forwarded-For", "203.0.113.1"), # Example valid IP
("X-Real-IP", "203.0.113.1"), # Example valid IP
]
opener = urllib.request.build_opener()
opener.addheaders = headers
Expand Down
4 changes: 4 additions & 0 deletions view/streamerResources/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
<span class="fas fa-user-circle"></span>
<strong><?php echo __('User'); ?>:</strong> <?php echo Login::getStreamerUser(); ?>
</p>
<p>
<span class="fa-solid fa-file-upload"></span>
<strong><?php echo __('Max File Size'); ?>:</strong> <?php echo get_max_file_size(); ?>
</p>
</div>
</div>

0 comments on commit b3ce6cb

Please sign in to comment.