When attempting to upload a file in development on Laravel 5 I get stream_socket_sendto(): error

Viewed 5322

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.

3 Answers

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

I had the same problem with the same environment. The thing was the file was too large, so it couldn't be uploaded to the temporary location. Although the 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 another reason why the file cannot be uploaded.

I solved it by changing size and memory limits in php.ini.

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

Besides size limits, I have one more suggestion: make sure that 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.

Related