Apache or nGinx? Are you restarted the server after editing the php.ini?
Uploading large dimension files
Is there a setting to limit the px dimensions of an uploaded file?
I'm using spatie Laravel Media Library. They say that there's no setting to limit this. My php.ini file has 5mb as the max upload size. But when I try to upload an image that's larger than 1500px, I get a 500 error.
@Waldemar - It's Apache.
you also need to consider the max post size
see also https://laracasts.com/discuss/channels/laravel/large-file-upload-gives-csrf-token-mismatch
All of the settings on the server are such that it wouldn't restrict the px dimensions of an image.
upload_max_filesize = 150M
post_max_size = 150M
memory_limit = 512M
max_execution_time = 1200
Try this parameters! Where 150M set your limit
I get a 500 error.
You could do just a little work and identify the reason for the 500 error. You know, like the exact error and the class/line number
In the log, there are about 50 entries. Multiple errors in Pipeline and Routes. There's one in Illuminate/Foundation/Http/Middleware/ValidatePostSize. I thought that might be one to look at. But the file doesn't exist.
@Waldemar - Thank you. I updated those parameters. Still having the problem.
This is the ValidatePostSize middleware: https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php
If you've already set post_max_size to something larger in your php.ini file I'm not sure why it would still show up. I would try echo ini_get('post_max_size'); in one of your views to verify that your new value is actually being read.
show me your form! Maybe you dont have multipart data? Try add enctype="multipart/form-data"
<form method="POST" action="/url" enctype="multipart/form-data">
If you have multipart! Try this
-
Create a .htaccess file in the root folder of web server.
-
Put the following code in side the .htaccess file and save it.
php_value upload_max_filesize 8M
php_value post_max_size 8M
php_value max_execution_time 200
php_value max_input_time 200
Sure. I have two forms. One for uploading:
<form action="file/save" method="post" enctype="multipart/form-data" target="_top">
{{-- start: Poster --}}
<label>Poster from File
<input type="file" name="poster_file" id="poster_file">
</label>
{{-- end: Poster --}}
<button>Replace image</button>
<input type="hidden" name="movie_id" value="{{ $movie->id }}">
{{ csrf_field() }}
</form>
And, one for getting an image from web:
<form action="web/save" method="post" target="_top">
<input type="text" name="poster_url">
<button>Refresh image</button>
<input type="hidden" name="movie_id" value="{{ $movie->id }}">
{{ csrf_field() }}
</form>
When I add that the my .htaccess file in the root of my server, I get a 500 error.
Ok! Try 1 and 3
- Maybe in .htaccess have error. Try commend all your lines
- Whong php.ini error (but i think no error)
- You dont have permission on your folder where upload
I commented all of the lines out of htaccess in the root of my server and placed your above suggestion there. I got the 500 Internal Server Error. I also tried the one in Laravel's public folder. Same thing. Didn't comment anything out there.
With regard to permissions, if I didn't have permission, I wouldn't be able to upload at all, though. Right? I only get the error for files larger than 1500px.
ohhh... Show me your rules for your form. Try add rule for form
$this->validate($request, [
'avatar' => 'dimensions:min_width=500,max_width=1500'
]);
If this does not work! in php.ini and restart server
upload_max_filesize = 1G
post_max_size = 1G
In the log, there are about 50 entries. Multiple errors in Pipeline and Routes. There's one in Illuminate/Foundation/Http/Middleware/ValidatePostSize. I thought that might be one to look at. But the file doesn't exist.
It's rare to see someone thinking too much and not enough at the same time.
What is the exact exception that you're getting? What line in what file is throwing it? What is being passed into the function that throws the exception?
If you can't answer all of those questions, just post the full stack trace for the exception and someone might figure it out for you.
When you look in the logs, the most recent error is at the bottom.
Simples!
It has nothing to do with uploading the file. It has to do with Laravel Media Library not able to handle images that size.
The files are uploading.
Well if Illuminate/Foundation/Http/Middleware/ValidatePostSize (source here) is still the error showing in your log, it's still a problem with the post_max_size in php.ini. If you put dd(ini_get('post_max_size')) somewhere in your code it should show you the value that middleware is using to determine if a post request is too large.
They say that there's no setting to limit this.
Use a library that has the requirements you need.
Why is everyone getting so short with me? This is a frustrating situation. That wasn't a constructive answer.
ok. How do you know the files are uploaded?
As far as I can see, you have not identified the exact error?
@Snapey earlier he said:
There's one in Illuminate/Foundation/Http/Middleware/ValidatePostSize. I thought that might be one to look at. But the file doesn't exist.
So I pointed him to the source for that middleware but I'm not sure if he ever looked at it. I think he either hasn't updated his ini to allow a larger post_max_size or his server process isn't reading the correct one.
So we are looking for something like PostTooLargeException in Illuminate/Foundation/Http/Middleware/ValidatePostSize.php ?
I've gotten it to store the files in storage/public. The files are being uploaded. It gives a 500 error every time Laravel Media Library tries to resize an image larger than 1500px high.
Here is the last line from my error log.
#46 /xx/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
Delete the log file completely and make the request one time so your log only contains all the details of that error, then share that here. One line isn't enough to go on.
OK, when you look at the error logs, it will start the stack trace and the last line in the log will be the top of the stack trace
You need to back track from the bottom of the file to the point where the error is thrown.
The lines will count down as you scroll up. The above is line #46 on the stack trace
Just curious, did OP never read this in the docs:
dimensions
The file under validation must be an image meeting the dimension constraints as specified by the rule's parameters:
'avatar' => 'dimensions:min_width=100,min_height=200'
Available constraints are: min_width, max_width, min_height, max_height, width, height, ratio.
A ratio constraint should be represented as width divided by height. This can be specified either by a statement like 3/2 or a float like 1.5:
'avatar' => 'dimensions:ratio=3/2'
Since this rule requires several arguments, you may use the Rule::dimensions method to fluently construct the rule:
use Illuminate\Validation\Rule;
Validator::make($data, [ 'avatar' => [ 'required', Rule::dimensions()->maxWidth(1000)->maxHeight(500)->ratio(3 / 2), ], ]);
@edoc referenced this in second answer.
@jlrdw I don't think you read the full thread correctly, he's not asking about how he can limit the dimensions, he's asking why it appears there appears to be a limit on the dimensions and thought maybe there was a setting he needs to turn off. It's not a validation rule question, but I can see why it first appears to be one.
more likely an out of memory issue when resizing
Please or to participate in this conversation.