在Laravel 5上尝试上传开发文件时,我得到stream_socket_sendto():error

I am trying a simple upload from a file so that a country has a sound file for its anthem attached. I am using PHP 7.2.10 with Laravel 5.7.19.

My form includes a field named anthem and the form commences with

<form id="form-app" enctype="multipart/form-data"
      method="post"
      action="{{ route('storeCountryAnthemMPOnly',['id' => $co->id]) }}">

The route in web.php is:

Route::post('storeCountryAnthemMPOnly/{id}',
            'CountryController@storeCountryAnthemMPOnly')
       ->name('storeCountryAnthemMPOnly');

and my function in the controller is just:

public function storeCountryAnthemMPOnly(Request $request, $id)
{
  dd($request);
}

When I press the submit button I am getting:

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.

I cannot understand this and help is greatly appreciated.

File can't be uploaded to the server and it is not fault of laravel, but your server.

I had exactly the same problem with the same environment. The thing was the file was too large, so it couldn't be uploaded to temporary location. Although file wasn't uploaded to the server, laravel still was trying to read it so this is why you get "no address was supplied".

In my case file couldn't be uploaded, because of exceeding size limits, but perhaps in your case it is other reason why file cannot be uploaded.

I solved it by changing limits in php.ini

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

Beside size limits I have one more suggestion: check do you have proper permissions to the folder with temporary uploads.

You can also check server logs.

You used Form::model style in your action URL. Change your action in form tag to

action="/storeCountryAnthemMPOnly/{{ $co->id }}"

Did you place a MAX_FILE_SIZE input in your form? If so, then you have to increase the value of it. I had the same problem and could fix it by just increasing the value to the proper one. This is the final size I put in.

<input type="hidden" name="MAX_FILE_SIZE" value="10485760">

I think Laravel is kindda checking this input in the back-scene.