Pages

24 July, 2023

Laravel: "Impossible to create the root directory" when storing file

I'm trying to store a file via AJAX to public folder in laravel, however when I submit the form I get the following message: " message: "Impossible to create the root directory \"C:\xampp\htdocs\Restaurante1\storage\app\C:/xampp/htdocs/Restaurante1/public/img\".", exception: "League\Flysystem\Exception", file: "C:\xampp\htdocs\Restaurante1\vendor\league\flysystem\src\Adapter\Local.php" I'm trying to store the file into the following folder inside public directory: public > img >uploads This is my JQuery code: console.log('new slider button clicked'); var formData = new FormData(); formData.append('title', $('#sliders_title').val()); formData.append('body', $('#sliders_body').val()); formData.append('isVisible', $('#sliders_isVisible').is(':checked') ? 1 : 0); formData.append('image', $('#sliders_image').prop('files')[0]); $.ajax({ async: true, url: '/sliders', type: 'POST', data: formData, dataType: 'JSON', processData: false, contentType: false, success: function (data) { $('.form_valid_container').html('✓ '+ data.success +''); form.trigger("reset"); console.log(data.success, data.errors); }, error: function (data){ var errors = data.responseJSON; console.log(errors); $.each(errors , function(){ $('.form_error_container').html('✘ '+ errors.message +'') }); } }); My controller method: public function store(StoreSlider $request) { $uploadFile = $request->file('image'); //generate random filename and append original extension (eg: asddasada.jpg, asddasada.png) $filename = str_random(6).'.'.$uploadFile->extension(); // storing path (Change it to your desired path in public folder) $path = 'img/uploads/'; // Move file to public filder $uploadFile->storeAs(public_path($path), $filename); $slider = new Slider(); $slider->title = $request->title; $slider->body = $request->body; $slider->image = $path.'/'.$filename; // So that you can access image by url($slider->image); $slider->isVisible = $request->isVisible; $slider->save(); return response()->json([ 'success' => 'Diapositiva guardada correctamente', 'slider' => $slider, ]); } EDIT: This is my config/filesystems

No comments:

Post a Comment

Thanks