示例#1
0
 public function upload()
 {
     // the file property can be empty if the field is not required
     if (null === $this->file) {
         return;
     }
     // we use the original file name here but you should
     // sanitize it at least to avoid any security issues
     // move takes the target directory and then the target filename to move to
     $this->file->move($this->getUploadRootDir(), $this->file->getClientOriginalName());
     // set the path property to the filename where you'ved saved the file
     $this->path = 'uploads/files/' . $this->getIssue()->getIssue() . '/' . $this->file->getClientOriginalName();
     // set the name property to the filename where you'ved saved the file
     $this->name = $this->file->getClientOriginalName();
     // clean up the file property as you won't need it anymore
     $this->file = null;
 }
示例#2
0
 /**
  * Uploads a file with a Document entity.
  *
  * @Route("/file/{issueid}/{sectionid}/upload_mm", name="file_upload_mm")
  * @Template("BorrowersIssueBundle:File:upload.html.twig")
  */
 public function uploadMmAction($issueid, $sectionid)
 {
     $securityContext = $this->get('security.context');
     $user = $securityContext->getToken()->getUser();
     $em = $this->getDoctrine()->getManager();
     $issue = $em->getRepository('BorrowersIssueBundle:Issue')->find($issueid);
     $section = $em->getRepository('BorrowersIssueBundle:Section')->find($sectionid);
     $options = array('issueid' => $issueid);
     $file = new File();
     $file->setIssue($issue);
     $file->setSortorder(1);
     $file->setUser($user);
     $file->setFileType(1);
     $form = $this->createForm(new UploadMmType($options), $file);
     $section->addFile($file);
     if ($this->getRequest()->getMethod() === 'POST') {
         $form->submit($this->getRequest());
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $file->upload();
             $em->persist($file);
             $em->flush();
             return $this->redirect($this->generateUrl('issue_show', array('id' => $issueid)));
         }
     }
     return array('form' => $form->createView());
 }