1

I used to upload images on the server without any problem, but after I installed spatie larave-image-optimizer I ran into some problems. I can upload any image that is less then 1MB, but anything over will break it

I tried to console log or dump an error so that I can see what's going on, but I don't understand what the error message is telling me.

$validate = Validator::make($request->all(), [
        'docs.*' => [
            'sometimes',
            'image',
            'mimes:jpeg,png,jpg,gif,svg',
            'max:51200',
        ],
    ]);

    if ($validate->fails()) {
        return response(['error' => 'Error!'], 422);
    }

    if ($request->file('docs')) {
        foreach ($request->file('docs') as $doc => $image) {
            $image->storeAs(
                '/folder/' . $id , //I get this id from the params
                $image->getClientOriginalName(),
                'public'
            );
        }
    }

This route goes through the image optimizer middleware

    Route::middleware('optimizeImages')->group(function () {
        Route::post("url", "...Controller@store");
    });`

I get this error:

    exception: "InvalidArgumentException"
    file: "{app_path}\vendor\spatie\image-> optimizer\src\Image.php"
    line: 14
    message: "`` does not exist"

Why does the 1MB image uplod, but one that is 2MB+ not? And how do I fix this behavior?

Keep in mind that before installing this package everything worked. I uploaded many images that are 4MB+, but I need them opimized so I use my server's disk efficiently.

EDIT #1 Error if i don't use the middleware:

    exception: "RuntimeException"
    file: "{app_path}\vendor\symfony\var-dumper\Server\Connection.php"
    line: 63
    message: "stream_socket_sendto(): A request to send or receive data was 
    disallowed because the socket is not connected and (when sending on a 
    datagram socket using a sendto call) no address was supplied.↵↵"
Darius Biro
  • 169
  • 1
  • 3
  • 12
  • Did you see the `package issue`? - https://github.com/spatie/laravel-image-optimizer/issues/67 – Rashed Hasan Oct 02 '19 at 20:06
  • I tried updating the sizes mentioned in that, but the error is the same... – Darius Biro Oct 02 '19 at 20:25
  • try to delete the `muddleware` group for testing – Joseph Oct 02 '19 at 20:29
  • I commented the middleware out and I get an other error: `exception: "RuntimeException" file: "{app_path}\vendor\symfony\var-dumper\Server\Connection.php" line: 63 message: "stream_socket_sendto(): A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.↵↵"` – Darius Biro Oct 02 '19 at 20:49
  • @Joseph a added the error in the q, so it is easier to red – Darius Biro Oct 02 '19 at 20:52
  • this package you installed make something wrong in your project delete this package from your composer file and delete your vendor folder then run `composer update` – Joseph Oct 02 '19 at 20:55

2 Answers2

3

go to your php.ini file and change those

upload_max_filesize = 10M
post_max_size = 10M

after that make sure you restart your apache server

Joseph
  • 5,644
  • 3
  • 18
  • 44
  • The error is the same. I even restarted my PC to make sure my apache server is restarted... – Darius Biro Oct 02 '19 at 20:24
  • It solved it... I was changeing the php.ini in my windows, not in XAMP. I had no ideea that those were different. After I changed those values in XAMP it worked as expected. Thank you so much. – Darius Biro Oct 03 '19 at 07:06
2

In your php.ini change values like -

memory_limit=32M
upload_max_filesize=24M
post_max_size=32M

Restart your server. Try with composer update. If not work, remove your spatie/laravel-image-optimizer and again install - composer require spatie/laravel-image-optimizer and then publish php artisan vendor:publish --provider="Spatie\LaravelImageOptimizer\ImageOptimizerServiceProvider"

Rashed Hasan
  • 3,721
  • 11
  • 40
  • 82
  • Thank you for your answer. Changind the `upload_max_filesize` and `post_max_size` worked. I had to change them in XAMP, not in my windows' php.ini file. Now I just have to change up on the server and it should work. – Darius Biro Oct 03 '19 at 07:08