Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jerauf's avatar

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.

0 likes
35 replies
Waldemar's avatar

Apache or nGinx? Are you restarted the server after editing the php.ini?

jerauf's avatar

All of the settings on the server are such that it wouldn't restrict the px dimensions of an image.

Waldemar's avatar
upload_max_filesize = 150M
post_max_size = 150M
memory_limit = 512M
max_execution_time = 1200

Try this parameters! Where 150M set your limit

Snapey's avatar

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

jerauf's avatar

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.

Waldemar's avatar

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

  1. Create a .htaccess file in the root folder of web server.

  2. 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
jerauf's avatar

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>
jerauf's avatar

When I add that the my .htaccess file in the root of my server, I get a 500 error.

Waldemar's avatar

Ok! Try 1 and 3

  1. Maybe in .htaccess have error. Try commend all your lines
  2. Whong php.ini error (but i think no error)
  3. You dont have permission on your folder where upload
jerauf's avatar

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.

Waldemar's avatar

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
36864's avatar

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.

Snapey's avatar

When you look in the logs, the most recent error is at the bottom.

Simples!

jerauf's avatar

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.

sutherland's avatar

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.

jlrdw's avatar

They say that there's no setting to limit this.

Use a library that has the requirements you need.

jerauf's avatar

Why is everyone getting so short with me? This is a frustrating situation. That wasn't a constructive answer.

Snapey's avatar

ok. How do you know the files are uploaded?

As far as I can see, you have not identified the exact error?

sutherland's avatar
Level 28

@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.

Snapey's avatar

So we are looking for something like PostTooLargeException in Illuminate/Foundation/Http/Middleware/ValidatePostSize.php ?

jerauf's avatar

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))

sutherland's avatar

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.

Snapey's avatar

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

jlrdw's avatar

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.

sutherland's avatar

@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.

Snapey's avatar

more likely an out of memory issue when resizing

1 like
Next

Please or to participate in this conversation.