Merge pull request #2363 from owncloud/uploadsize

Improve behaviour when max upload size is unknown
This commit is contained in:
Bernhard Posselt 2013-03-18 08:18:27 -07:00
commit 5b1f857907
4 changed files with 22 additions and 5 deletions

View File

@ -47,7 +47,7 @@ $totalSize = 0;
foreach ($files['size'] as $size) {
$totalSize += $size;
}
if ($totalSize > $maxUploadFilesize) {
if ($maxUploadFilesize >= 0 and $totalSize > $maxUploadFilesize) {
OCP\JSON::error(array('data' => array('message' => $l->t('Not enough storage available'),
'uploadMaxFilesize' => $maxUploadFilesize,
'maxHumanFilesize' => $maxHumanFilesize)));

View File

@ -23,8 +23,10 @@
method="post"
enctype="multipart/form-data"
target="file_upload_target_1">
<?php if($_['uploadMaxFilesize'] >= 0):?>
<input type="hidden" name="MAX_FILE_SIZE" id="max_upload"
value="<?php p($_['uploadMaxFilesize']) ?>">
<?php endif;?>
<!-- Send the requesttoken, this is needed for older IE versions
because they don't send the CSRF token via HTTP header in this case -->
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" id="requesttoken">

View File

@ -30,6 +30,7 @@
namespace OC\Files;
const FREE_SPACE_UNKNOWN = -2;
const FREE_SPACE_UNLIMITED = -3;
class Filesystem {
public static $loaded = false;

View File

@ -764,9 +764,15 @@ class OC_Helper {
public static function maxUploadFilesize($dir) {
$upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$freeSpace = \OC\Files\Filesystem::free_space($dir);
if ($upload_max_filesize == 0 and $post_max_size == 0) {
$maxUploadFilesize = \OC\Files\FREE_SPACE_UNLIMITED;
} elseif ($upload_max_filesize === 0 or $post_max_size === 0) {
$maxUploadFilesize = max($upload_max_filesize, $post_max_size); //only the non 0 value counts
} else {
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
}
if($freeSpace !== \OC\Files\FREE_SPACE_UNKNOWN){
$freeSpace = max($freeSpace, 0);
@ -806,11 +812,19 @@ class OC_Helper {
$used = 0;
}
$free = \OC\Files\Filesystem::free_space();
$total = $free + $used;
if ($free >= 0){
$total = $free + $used;
} else {
$total = $free; //either unknown or unlimited
}
if ($total == 0) {
$total = 1; // prevent division by zero
}
$relative = round(($used / $total) * 10000) / 100;
if ($total >= 0){
$relative = round(($used / $total) * 10000) / 100;
} else {
$relative = 0;
}
return array('free' => $free, 'used' => $used, 'total' => $total, 'relative' => $relative);
}