mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 02:45:58 +00:00
Added max file size for uploads.
This commit is contained in:
@@ -16,6 +16,7 @@ use Input;
|
|||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
|
use Steam;
|
||||||
use URL;
|
use URL;
|
||||||
use View;
|
use View;
|
||||||
|
|
||||||
@@ -44,6 +45,9 @@ class TransactionController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function create(AccountRepositoryInterface $repository, $what = 'deposit')
|
public function create(AccountRepositoryInterface $repository, $what = 'deposit')
|
||||||
{
|
{
|
||||||
|
$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']));
|
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
||||||
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
|
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
|
||||||
$budgets[0] = trans('form.noBudget');
|
$budgets[0] = trans('form.noBudget');
|
||||||
@@ -69,7 +73,7 @@ class TransactionController extends Controller
|
|||||||
asort($piggies);
|
asort($piggies);
|
||||||
|
|
||||||
|
|
||||||
return view('transactions.create', compact('accounts', 'budgets', 'what', 'piggies', 'subTitle'));
|
return view('transactions.create', compact('accounts', 'uploadSize', 'budgets', 'what', 'piggies', 'subTitle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,6 +126,9 @@ class TransactionController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal)
|
public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
|
$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);
|
$what = strtolower($journal->transactionType->type);
|
||||||
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
||||||
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
|
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
|
||||||
@@ -180,7 +187,7 @@ class TransactionController extends Controller
|
|||||||
Session::forget('transactions.edit.fromUpdate');
|
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:
|
// save attachments:
|
||||||
$att->saveAttachmentsForModel($journal);
|
$att->saveAttachmentsForModel($journal);
|
||||||
|
|
||||||
// one error
|
// flash errors
|
||||||
if ($att->getErrors()->count() == 1) {
|
if (count($att->getErrors()->get('attachments')) > 0) {
|
||||||
Session::flash('error', join('', $att->getErrors()->get('attachments')));
|
Session::flash('error', $att->getErrors()->get('attachments'));
|
||||||
}
|
}
|
||||||
|
// flash messages
|
||||||
if ($att->getErrors()->count() > 1) {
|
if (count($att->getMessages()->get('attachments')) > 0) {
|
||||||
// todo moet beter
|
Session::flash('info', $att->getMessages()->get('attachments'));
|
||||||
Session::flash('error', '<ul class="list-unstyled">' . join('', $att->getErrors()->get('attachments', '<li>:message</li>')) . '</ul>');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($att->getMessages()->count() > 0) {
|
|
||||||
// todo moet beter
|
|
||||||
Session::flash('info', '<ul class="list-unstyled">' . join('', $att->getMessages()->get('attachments', '<li>:message</li>')) . '</ul>');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event(new JournalSaved($journal));
|
event(new JournalSaved($journal));
|
||||||
|
@@ -90,4 +90,33 @@ class Steam
|
|||||||
return $result;
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ return [
|
|||||||
'update_attachment' => 'Update attachment',
|
'update_attachment' => 'Update attachment',
|
||||||
'delete_attachment' => 'Delete attachment ":name"',
|
'delete_attachment' => 'Delete attachment ":name"',
|
||||||
'attachment_deleted' => 'Deleted attachment ":name"',
|
'attachment_deleted' => 'Deleted attachment ":name"',
|
||||||
|
'upload_max_file_size' => 'Maximum file size: :size',
|
||||||
|
|
||||||
// tour:
|
// tour:
|
||||||
'prev' => 'Prev',
|
'prev' => 'Prev',
|
||||||
|
@@ -19,8 +19,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if Session.get('info') is iterable and Session.get('info')|length == 1 %}
|
{% if Session.get('info') is iterable and Session.get('info')|length == 1 %}
|
||||||
<strong>Message:</strong>
|
<strong>Message:</strong> {{ Session.get('info')[0]|raw }}
|
||||||
{{ Session.get('info')[0]|raw }}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if Session.get('info') is not iterable %}
|
{% if Session.get('info') is not iterable %}
|
||||||
|
@@ -75,7 +75,7 @@
|
|||||||
{{ ExpandedForm.select('piggy_bank_id',piggies) }}
|
{{ ExpandedForm.select('piggy_bank_id',piggies) }}
|
||||||
|
|
||||||
<!-- ATTACHMENTS -->
|
<!-- ATTACHMENTS -->
|
||||||
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple'}) }}
|
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -76,7 +76,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- ATTACHMENTS -->
|
<!-- ATTACHMENTS -->
|
||||||
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple'}) }}
|
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user