Skip to content

Firefly III: a personal finances manager

Added max file size for uploads.

James Cole4dbc135dcec0
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index 5458193e5d..11316ffef3 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -16,6 +16,7 @@ use Input;
use Preferences;
use Response;
use Session;
+use Steam;
use URL;
use View;
@@ -44,14 +45,17 @@ class TransactionController extends Controller
*/
public function create(AccountRepositoryInterface $repository, $what = 'deposit')
{
- $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
- $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
- $budgets[0] = trans('form.noBudget');
- $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get());
- $piggies[0] = trans('form.noPiggybank');
- $preFilled = Session::has('preFilled') ? Session::get('preFilled') : [];
- $respondTo = ['account_id', 'account_from_id'];
- $subTitle = trans('form.add_new_' . $what);
+ $maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
+ $maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
+ $uploadSize = min($maxFileSize, $maxPostSize);
+ $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
+ $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
+ $budgets[0] = trans('form.noBudget');
+ $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get());
+ $piggies[0] = trans('form.noPiggybank');
+ $preFilled = Session::has('preFilled') ? Session::get('preFilled') : [];
+ $respondTo = ['account_id', 'account_from_id'];
+ $subTitle = trans('form.add_new_' . $what);
foreach ($respondTo as $r) {
$preFilled[$r] = Input::get($r);
@@ -69,7 +73,7 @@ class TransactionController extends Controller
asort($piggies);
- return view('transactions.create', compact('accounts', 'budgets', 'what', 'piggies', 'subTitle'));
+ return view('transactions.create', compact('accounts', 'uploadSize', 'budgets', 'what', 'piggies', 'subTitle'));
}
/**
@@ -122,14 +126,17 @@ class TransactionController extends Controller
*/
public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal)
{
- $what = strtolower($journal->transactionType->type);
- $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
- $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
- $budgets[0] = trans('form.noBudget');
- $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get());
- $piggies[0] = trans('form.noPiggybank');
- $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
- $preFilled = [
+ $maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
+ $maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
+ $uploadSize = min($maxFileSize, $maxPostSize);
+ $what = strtolower($journal->transactionType->type);
+ $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
+ $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
+ $budgets[0] = trans('form.noBudget');
+ $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get());
+ $piggies[0] = trans('form.noPiggybank');
+ $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
+ $preFilled = [
'date' => $journal->date->format('Y-m-d'),
'category' => '',
'budget_id' => 0,
@@ -180,7 +187,7 @@ class TransactionController extends Controller
Session::forget('transactions.edit.fromUpdate');
- return view('transactions.edit', compact('journal', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled);
+ return view('transactions.edit', compact('journal', 'uploadSize', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled);
}
/**
@@ -321,20 +328,13 @@ class TransactionController extends Controller
// save attachments:
$att->saveAttachmentsForModel($journal);
- // one error
- if ($att->getErrors()->count() == 1) {
- Session::flash('error', join('', $att->getErrors()->get('attachments')));
- }
-
- if ($att->getErrors()->count() > 1) {
- // todo moet beter
- Session::flash('error', '<ul class="list-unstyled">' . join('', $att->getErrors()->get('attachments', '<li>:message</li>')) . '</ul>');
+ // flash errors
+ if (count($att->getErrors()->get('attachments')) > 0) {
+ Session::flash('error', $att->getErrors()->get('attachments'));
}
-
-
- if ($att->getMessages()->count() > 0) {
- // todo moet beter
- Session::flash('info', '<ul class="list-unstyled">' . join('', $att->getMessages()->get('attachments', '<li>:message</li>')) . '</ul>');
+ // flash messages
+ if (count($att->getMessages()->get('attachments')) > 0) {
+ Session::flash('info', $att->getMessages()->get('attachments'));
}
event(new JournalSaved($journal));
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index f5f8e3f61f..4f49117f7b 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -90,4 +90,33 @@ class Steam
return $result;
}
+ // parse PHP size:
+ /**
+ * @param $string
+ *
+ * @return int
+ */
+ public function phpBytes($string)
+ {
+ $string = strtolower($string);
+
+ if (!(strpos($string, 'k') === false)) {
+ // has a K in it, remove the K and multiply by 1024.
+ $bytes = bcmul(rtrim($string, 'k'), 1024);
+
+ return intval($bytes);
+ }
+
+ if (!(strpos($string, 'm') === false)) {
+ // has a M in it, remove the M and multiply by 1048576.
+ $bytes = bcmul(rtrim($string, 'm'), 1048576);
+
+ return intval($bytes);
+ }
+
+ return $string;
+
+
+ }
+
}
diff --git a/resources/lang/en/firefly.php b/resources/lang/en/firefly.php
index 69b5fa0190..8dd038faa6 100644
--- a/resources/lang/en/firefly.php
+++ b/resources/lang/en/firefly.php
@@ -26,6 +26,7 @@ return [
'update_attachment' => 'Update attachment',
'delete_attachment' => 'Delete attachment ":name"',
'attachment_deleted' => 'Deleted attachment ":name"',
+ 'upload_max_file_size' => 'Maximum file size: :size',
// tour:
'prev' => 'Prev',
diff --git a/resources/twig/partials/flashes.twig b/resources/twig/partials/flashes.twig
index 5cfc0ae4ca..f62c45ce61 100644
--- a/resources/twig/partials/flashes.twig
+++ b/resources/twig/partials/flashes.twig
@@ -19,8 +19,7 @@
</ul>
{% endif %}
{% if Session.get('info') is iterable and Session.get('info')|length == 1 %}
- <strong>Message:</strong>
- {{ Session.get('info')[0]|raw }}
+ <strong>Message:</strong> {{ Session.get('info')[0]|raw }}
{% endif %}
{% if Session.get('info') is not iterable %}
diff --git a/resources/twig/transactions/create.twig b/resources/twig/transactions/create.twig
index f88e569f29..73832b0149 100644
--- a/resources/twig/transactions/create.twig
+++ b/resources/twig/transactions/create.twig
@@ -75,7 +75,7 @@
{{ ExpandedForm.select('piggy_bank_id',piggies) }}
<!-- ATTACHMENTS -->
- {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple'}) }}
+ {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
</div>
diff --git a/resources/twig/transactions/edit.twig b/resources/twig/transactions/edit.twig
index a9a20bc978..524e0df51d 100644
--- a/resources/twig/transactions/edit.twig
+++ b/resources/twig/transactions/edit.twig
@@ -76,7 +76,7 @@
{% endif %}
<!-- ATTACHMENTS -->
- {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple'}) }}
+ {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
</div>
</div>