Home > Net >  Laravel Uploading Image with small file size and big file size
Laravel Uploading Image with small file size and big file size

Time:01-02

I am developing a photo gallery and having the problem that I get following error message after trying to upload images which are far bigger (70mb) than those which are working (5-10mb). Error Message: stream_copy_to_stream(): Read of 8192 bytes failed with errno=21 Is a directory

I also changed inside the php.ini file the max upload size to over 1000m but I am getting still the same error message.

Do you have any idea why I am getting the error message?

CodePudding user response:

This is related to the PHP settings. The error is not clear in this case, but likely you just need to increase these variables on your PHP.ini file:

  • upload_max_filesize
  • post_max_size memory_limit

CodePudding user response:

I also think that it's a php settings related issue.
You can temporarily change the php.ini configuration directly in your method like below.

public function upload()
{
    ini_set('memory_limit','2024M');
    ini_set('post_max_size','2024M');
    ini_set('upload_max_filesize','2024M');
    ini_set('max_input_time', 36000); // 10 houres
    set_time_limit(36000); // 10 houres

    // your image upload related logic
}

Instead of changing the php.ini file, you can alter the settings only for certain routes. You can define the custom settings directly in you controller method like above, Or you can set it in the constructor of that controller.

  • Related