I'm using Laravel5.1 and tinyMCE with laravel file manager (unisharp) and I'm always getting this error when I'm uploading big files (e.g. 20MB and up). I've searched about it on internet but I didn't find something similar with my problem. Please see my code for your review.
Code:
<div class="input-group">
<input type="text" name="file_path" id="file_path" class="form-control" value="{{ Request::old('file_path') }}" readonly>
<a id="lfm" class="input-group-addon btn btn-primary" data-input="file_path">
<i class="fa fa-file"></i> Choose file...
</a>
</div>
Script:
<script>
getTiny('{{ URL::to('/') }}', 'textarea'); // customized function for tinyMCE
{!! \File::get(base_path('vendor/unisharp/laravel-filemanager/public/js/lfm.js')) !!}
var domain = "{{ URL::to('/') }}/laravel-filemanager";
$('#lfm').filemanager('file', {prefix: domain});
</script>
Try to set a larger upload_max_filesize in php.ini, see here. Or any corresponding configs of your server like NginX or Apache.
Related
I'm running laravel 5.7, I changed the sessions to the database. I did make:auth and tried to register and got an error page with
"The page has expired due to inactivity. Please refresh and try again"
I have been at this for a couple of days now. I added /register to the except array to bypass the verify token and was able to register. Now I'm trying to login and get the same issue. I have **cleared cache, checked settings, switched back to file, tried other browsers, verified the token was in the form, make sure it was in the header, made sure it was getting passed and still nothing. I added this to the Handler class in Exceptions:
if ($exception instanceof \Illuminate\Session\TokenMismatchException) {
return redirect()->back()->with('error_message',"Oops! Seems there was an error with login. Please try again or contact us.");
}
and this leaves me to believe the token is not matching because it redirects instead of going to the broken page. I have read through I think every article on the internet and cannot figure this out. My next option is to start fresh with a new install unless anyone has any idea what could cause this?
This was on my local. I have not pushed anything to production.
Edited to add Form:
{!! Form::open(['route' => 'login', 'method' => 'post']) !!}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-12">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-12">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 offset-md-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">Login </button>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
{!! Form::close() !!}
Try using a different browser to login or an incognito window.
Also remember on any form where you are POST-ing to use the #csrf in your blade file.
This problem comes from CSRF token validation which fails:
'The page has expired due to inactivity. Please refresh and try
again.'
you should include a hidden CSRF token field in the form so that the CSRF protection middleware can validate the request.
<form method="POST" action="/profile">
#csrf
...
</form>
It doesn't work, then Refresh the browser cache and now it might work
There should not accure any errors, so if you only want to create the auth scaffolding I would suggest just to create a new laravel project.
Do following steps:
laravel new app
create the database
Add the database credentials to your .env file
run php artisan:migrate in your command line, inside your project, that should create you a users table
run php artisan make:auth, that is going to create the basic auth logic
Lastly run php artisan migrate again
In case someone in the future comes here and tries all the solutions out there and they dont work I wanted to share what finally worked for me. I started by installing a new instance of laravel 5.8. I did make:auth and checked that the standard forms works as expected. I then added in the code from the instance that was not working which was basically my custom app.blade.php, header.blade.php,footer.blade.php,welcome.blade.php register.blade.php, helpers.php ( contains my custom helper functions ) and updated composer.json with the packages I use. I ran composer update and it did not work. I went back to the beginning and added each piece individually until I found the issue. I am not sure why this happened but the issue was this:
I have a custom file within app/ called helpers.php. I add it via composer.json like this:
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Http/helpers.php"
]
},
I have one function in there that I use to wrap files in that adds in my aws S3 endpoint. Thats it. But for some reason this was causing the site to redirect on every page load back to itself and give me a new session. I would refresh over and over and just watch the session files accumulate. I read that the helper functions are getting deprecated in 5.9 so I went ahead and created a provider then use that in place of my helper function which did the trick.
If someone knows why this happens I would love to hear it. But if you have this issue, open up the sessions folder in your editor and see if you keep getting new sessions. If so then backtrack and see whats causing it to reroute.
I have a form with two text fields and two buttons (edit and delete), when I press edit button, it works fine but when I press delete button, it gives the 'MethodNotAllowedHttp' exception. My code is as follows:
<form action="/laboratory/doctors/update" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" aria-describedby="name" value="{{ $doctor->name }}">
</div>
<div class="form-group">
<label for="percentage">Percentage:</label>
<input type="text" class="form-control" id="percentage" value="{{ $doctor->percentage }}">
</div>
<button type="submit" class="btn btn-success">Save Changes</button>
Delete
</form>
My Routes are as follows:
Route::post('/doctors/update', 'DoctorsController#update');
Route::delete('/doctors/{doctor}/delete', 'DoctorsController#destroy');
Any help is appreciated.
You have created route of http verbs as delete type and trying to get of type get. So you can change it as get instead delete
Route::get('/laboratory/doctors/{doctor}/delete', 'DoctorsController#destroy');
Also there is other way to make http verb as DELETE but using
Another form tag outside of current form tag.
Or use ajax to make it delete type
Href on an anchor html element will result in a GET call but your route expect a Delete call. You have some ways to make sure you will result in a delete call.
One of the most common ways is to use a form instead to post data to your server.
DELETE
{{ Form::open(['url' => '/laboratory/doctors/{{ $doctor->id }}/delete', 'method' => 'DELETE']) }}
{{ Form::button('delete', ['type' => 'submit',
'class' => 'btn btn-danger']) }}
{{ Form::close() }}
For best practise I recommend to use {{ Form::open(...) }} {{ Form::close() }} only once and refactor your controller code so it can read the value from the buttons and translate that in the corresponding {doctor} of the delete post so you dont have multiple html forms in your code.
#if(isset($doctor))
<form action="/laboratory/doctors/{{$doctor->id}}/delete" method="POST">
#else
<form action="/laboratory/doctors/update" method="POST">
#endif
{{ csrf_field() }}
#if(isset($doctor))
{{ method_field('DELETE') }}
#endif
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" aria-describedby="name" value="{{ $doctor->name }}">
</div>
<div class="form-group">
<label for="percentage">Percentage:</label>
<input type="text" class="form-control" id="percentage" value="{{ $doctor->percentage }}">
</div>
<button type="submit" class="btn btn-success">Save Changes</button>
Delete
</form>
The problem is in your action.. when you click delete button, the button run the destroy function, but the form run the update function. So, you have to separate the form action, or you can delete it by using ajax
I'm using a nice HTML template which features a preview of the picture selected by my HTML file input. This is the HTML:
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new img-thumbnail text-center">
<img src="#" data-src="holder.js/100%x100%" alt="not found"></div>
<div class="fileinput-preview fileinput-exists img-thumbnail"></div>
<div class="m-t-20 text-center">
<span class="btn btn-primary btn-file">
<span class="fileinput-new">choose</span>
<span class="fileinput-exists">change</span>
<input type="file" id="pb" name="pb" accept="image/*" class="form-control"></span>
<a href="#" class="btn btn-warning fileinput-exists"
data-dismiss="fileinput">Entfernen</a>
</div>
</div>
I chose pb as name for the actual file input. This is the controller function:
public function addUser(Request $request) {...}
Everything fine so far, echo $request->pb also echoes the filename as desired. HOWEVER, Laravel doesn't recognise this as a file apparently:
$request->file('pb')
returns null (yes, I have tried to display all files of $request, also $request->hasFile() returns false/null). I wonder why? Unfortunately, I cannot directly access $_FILE which would make things easier despite not being in the right order with Laravel in general.
Make sure your form has:
enctype="multipart/form-data"
I was working on my project normally and when i hit refresh to see a change that i just made in one of the html pages, the page showed a text on top left "Redirecting to: http://localhost:8888/xxx ". It redirected me to the login page. When i clicked login, the 'TokenMismatchException' error showed:
The login form has the hidden input _token , header has it too. As i said everything was fine. I have been working on this project for 2 months. Is this related to files permissions ?
Here is the login form.
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-7">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-7">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ url('/password/reset') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
Thanks :)
After i installed a fresh laravel copy i started to paste my old files to see where would regenerate the mismatch token problem.
It went down to the routes/web.php file. Something there was causing the error. It was a space before the opening tag of php on routes/web.php file.
Something that did not caught my eye. Like that the project was working fine but suddenly did not anymore.
As i read , the space is considered an output. Check this explanation :
https://stackoverflow.com/a/4345822/6634389
Why don't you use {{ csrf_field() }} or try with that?
Run:
php artisan cache:clear; composer dump-autoload; composer clear-cache
Refresh the browser, make sure you generated the key for your app. This should work. For me it did.
You are refreshing your page, so each time the pages load with same csrf-token. So when you are trying to post your data, laravel refuses it and provide error message due to each request should have a unique csrf-token. You can read about this herelaravekl csrf protection
Either you should again reload your page or you should disable the csrf protection by commenting it inside the
App=>Http=>Kernel.php
inside the $middlewareGroups=>'web'
\App\Http\Middleware\VerifyCsrfToken::class, //comment this line
I was having the same issue, I solved it by using following in my view
<input type="hidden" name="_token" value="{{ session()->getToken() }}">
I installed greggilbert/recaptcha in my laravel 5.2 project. I followed the direction accordingly described here:https://github.com/greggilbert/recaptcha
But when I opened the form where I used recaptcha, I found the above message.
I read the source code but understand nothing.
Can anybody help me in this regard to find any solution?
Thanks in advance.
Here is my form HTML Code
#section('form')
{{ Form::open(array('url' => 'contact')) }}
<div class="panel-body">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-comment blue"></i></span>
<textarea name="InputMessage" rows="6" class="form-control" required placeholder="Message"></textarea>
</div>
</div>
{!! Recaptcha::render() !!}
<div class="">
<button type="submit" class="btn btn-info pull-right">Send <span class="glyphicon glyphicon-send"></span></button>
<button type="reset" value="Reset" name="reset" class="btn">Reset <span class="glyphicon glyphicon-refresh"></span></button>
</div>
</div>
{{Form::close()}}
#endsection
The Problem is solved.
The problem was:
php artisan vendor:publish --provider="Greggilbert\Recaptcha\RecaptchaServiceProvider"`
command did nothing.
So recaptcha.php file was not copied to root config folder.
I copied the recaptcha.php file from
vendor > greggilbert > recaptcha > src > config > recaptcha.php`
to config folder and the problem disappears.
After vendor publishing you need to clear config cache using command
php artisan config:cache