I have configured the uploading of images correctly in the admin and followed this documentation: link
Now in another part of the system that does not use EasyAdminBundle I need to upload images, in the controller I have this:
public function crearequiposAction(Request $request) {
$equipo = new Equipos();
$form = $this->createForm(EquiposType::class, $equipo);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$fecha=new \DateTime('now');
$ruta = $equipo->getImageFile();
$nombrep = $equipo->getLogo();
$nombre = $nombrep.'.'.$ruta->guessExtension();
$fileDir = $this->container->getParameter('kernel.root_dir').'/../web/uploads/images/equipos';
$ruta->move(
$fileDir,
$nombre
);
$equipo->setLogo($nombre);
$equipo->setUpdatedAt($fecha);
$em->persist($equipo);
$flush = $em->flush();
if ($flush == null) {
$status = "Documento registrado correctamente";
$this->session->getFlashBag()->add("status", $status);
return $this->redirectToRoute("listado-torneos");
} else {
$status = "No se registro equipo";
}
} else {
$status = "No se registro equipo";
}
$this->session->getFlashBag()->add("status", $status);
}
return $this->render('AppBundle:Equipos:informacionequipos.html.twig', array(
"form" => $form->createView()
));
}
The image uploads correctly but it shows me this error:
The file "test.jpeg" was not uploaded due to unknown error.
And I do not know how to solve this problem, any ideas?
Greetings