Skip to content

Commit

Permalink
File classes does not use the $FILES array directly, as users of this…
Browse files Browse the repository at this point in the history
… class aren't necessarily from the web
  • Loading branch information
candrews committed Jul 7, 2009
1 parent a9c83b0 commit 5f72423
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion actions/newnotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function getUploadedFileType() {

function isRespectsQuota($user) {
$file = new File;
$ret = $file->isRespectsQuota($user);
$ret = $file->isRespectsQuota($user,$_FILES['attach']['size']);
if (true === $ret) return true;
$this->clientError($ret);
}
Expand Down
10 changes: 5 additions & 5 deletions classes/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,25 @@ function processNew($given_url, $notice_id) {
return $x;
}

function isRespectsQuota($user) {
if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) {
function isRespectsQuota($user,$fileSize) {
if ($fileSize > common_config('attachments', 'file_quota')) {
return sprintf(_('No file may be larger than %d bytes ' .
'and the file you sent was %d bytes. Try to upload a smaller version.'),
common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
common_config('attachments', 'file_quota'), $fileSize);
}

$query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'";
$this->query($query);
$this->fetch();
$total = $this->total + $_FILES['attach']['size'];
$total = $this->total + $fileSize;
if ($total > common_config('attachments', 'user_quota')) {
return sprintf(_('A file this large would exceed your user quota of %d bytes.'), common_config('attachments', 'user_quota'));
}

$query .= ' month(modified) = month(now()) and year(modified) = year(now())';
$this->query($query);
$this->fetch();
$total = $this->total + $_FILES['attach']['size'];
$total = $this->total + $fileSize;
if ($total > common_config('attachments', 'monthly_quota')) {
return sprintf(_('A file this large would exceed your monthly quota of %d bytes.'), common_config('attachments', 'monthly_quota'));
}
Expand Down

0 comments on commit 5f72423

Please sign in to comment.