1
When trying to upload an image to Laravel on a web server it is not generating the image. When using $request->hasFile('image') even if the image is being sent but if I run the same project on the local server it works normally
This is the return of the request on the web server (000webhostapp.com)
This is the return of the request on the local server(Xampp)
On the web server it does not upload the image regardless of the image extension or the size
I created a function where I upload the image where I pass my request and the object where I want to insert the image:
protected function uploadImage($request, $post){ if ($request->hasFile('imagem')) { $id = $post->id; $image = $request->imagem; if (!is_null($image)){ $file = $image; $extension = $image->getClientOriginalExtension(); $type = 'posts'; $fileName = time() . random_int(100, 999) .'.' . $extension; $destinationPath = public_path('image/'.$type.'/'.$id.'/'); $url = '/image/'.$type.'/'.$id.'/'.$fileName; $fullPath = $destinationPath.$fileName; if (!file_exists($destinationPath)) { File::makeDirectory($destinationPath, 0775); } $image = Image::make($file); $image->save($fullPath, 100); return $url; }else{ return $post->post_midia_url; } } }
I changed the filesystems.php file configuration by adding the ftp configuration and also added it in . env