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

Ligonsker's avatar

How to check if $file->store() was successful?

I have some issues when trying to store files. It randomly works or not:

if ($request->hasFile('files')) {
        foreach ($request->file('files') as $file) {
        $file->store('folder');
    }
}

I have set max upload file size on both php.ini and nginx.conf and I did manage to upload files of up to 5MB.

But then it just either works or not, so I am not sure if it's permissions issues or something else. There is nothing in the logs

Maybe I can somehow check the $file->store('folder'); and it will return some meaningful response? Or some other way?

0 likes
6 replies
Ligonsker's avatar

@Sinnbeck Thanks, I did it but I don't see anything yet. I just realized that it might be related to file size after all.

Because earlier I was receiving 413 Request Entity Too Large then I added client_max_body_size 100M; to my nginx.conf http block and it stopped giving me this error.

I also have the following in php.ini:

post_max_size 128M
upload_max_filesize 20M
memory_limit 128M

So now, I noticed it uploads small files <1MB but when I try to upload 3.5MB file it won't work

Sinnbeck's avatar

@Ligonsker I have never seen it not throw an error when a file is too large. What exactly happens with the larger file when it "won't work" ?

Ligonsker's avatar

@Sinnbeck it just doesn't store the file in the specified folder

I just checked by uploading 2 files close to the limit of the default PHP upload max size with is 2MB and that see to be the issue: I created a 1950KB file and 2100KB file, and it sucesfuly uploaded the 1950KB file but not the 2100KB file.

I just wonder why because my php.ini at /etc/php/8.1/fpm/php.ini is set to upload_max_filesize = 20M now

Sinnbeck's avatar

@Ligonsker I was just working with exactly the same two weeks ago, and I raised both php and nginx to 512mb, and was able to upload a 500mb file without any problems. I will try and think of any reason it wouldn't throw an error. Can you share the complete controller method ?

1 like
Ligonsker's avatar

@Sinnbeck This is the complete method :D

I made it work! I also had to restart the fpm service:

sudo systemctl restart php8.1-fpm

Now I have another issue though, but that's related to WireGuard - the uploads don't work when trying from devices outside the localhost

Update: I think I figured out the issue! Since I am using WireGuard as a proxy_pass, then I have 2 nginx running - one on the AWS EC2 machine and one locally.

I did not configure the remote EC2 nginx config and there it's still the 1MB default

Please or to participate in this conversation.