Image not uploading public function store(Request $request)
{
$this->validate($request,[
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048'
]);
$image = $request->file('image');
$name = rand().'.'.$image->getClientOriginalExtension();
if(file_exists(public_path("images2")))
{
$image->move(public_path("images2"),$name);
}
else
{
$image->move(public_path(mkdir("images2")),$name);
}
}
In the above code if directory exists then the image is moving to the path. Else block code not working only directory is created but image is not moving.
This
else
{
$image->move(public_path(mkdir("images2")),$name);
}
expects the path to be returned from the mkdir command. it probably returns true or false.
alter the logic
$image = $request->file('image');
$name = rand().'.'.$image->getClientOriginalExtension();
if(! file_exists(public_path("images2")))
{
public_path(mkdir("images2");
}
$image->move(public_path("images2"),$name);
Please sign in or create an account to participate in this conversation.