public function logoeditAction(Request $request) { $id = $request->get('id'); $em = $this->getDoctrine()->getManager(); $imageo = $em->getRepository('AcmeInfoBundle:Logo')->find($id); $image = new \Acme\InfoBundle\Entity\Logo(); $image->setLogo(''); $image->setStatus(''); $form = $this->createFormBuilder($image)->add('logo', 'file')->add('status', 'checkbox', array('mapped' => false, 'required' => false, 'error_bubbling' => true, 'data' => $imageo->getStatus() == 1 ? TRUE : FALSE))->getForm(); $form->handleRequest($request); $validator = $this->get('validator'); $errors = $validator->validate($image); if (count($errors) > 1) { return $this->render('AcmeInfoBundle:Default:logoedit.html.twig', array('form' => $form->createView(), 'id' => $id, 'logo' => $imageo->getLogo())); } else { if ($request->isMethod('POST') == 'POST') { if ($_FILES['form']['name']['logo'] != NULL) { $a = $request->request->get('form'); $dir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/logo/'; $em = $this->getDoctrine()->getManager(); $image = $em->getRepository('AcmeInfoBundle:Logo')->find($id); $old_image = $image->getLogo(); unlink($_SERVER['DOCUMENT_ROOT'] . '/uploads/logo/' . $old_image); $new_image = rand() . '_' . $form['logo']->getData()->getClientOriginalName(); $image = $this->getDoctrine()->getRepository('AcmeInfoBundle:Logo')->find($request->get('id')); $image->setLogo($new_image); if ($a['status'] == 1) { $image->setStatus($a['status']); } else { $image->setStatus(0); } $em->flush(); $form->get('logo')->getData()->move($dir, $new_image); return $this->redirect($this->generateUrl('acme_info_logo')); } else { return $this->redirect($this->generateUrl('acme_info_logo')); } } return $this->render('AcmeInfoBundle:Default:logoedit.html.twig', array('form' => $form->createView(), 'id' => $id, 'logo' => $imageo->getLogo())); } }