public function addFileAction(Request $request) { $files = $this->getRequest()->files; $em = $this->getDoctrine()->getManager(); if (!empty($files)) { $user = $this->get('security.context')->getToken()->getUser(); $dir = $this->get('kernel')->getRootDir() . '/../web/uploads/'; foreach ($files as $f) { $filename = $f->getClientOriginalName(); $extension = pathinfo($filename, PATHINFO_EXTENSION); $name = "file" . rand(1, 99999) . "platin" . "." . $extension; $file = $f->move($dir, $name); $pathFile = "uploads/" . $name; $file = new File(); $file->setName($filename); $file->setCreationdate(new \DateTime()); $file->setUser($user); $file->setPathFile($pathFile); $file->setDate(new \Datetime()); $file->setTime(new \Datetime()); $file->setActive(0); $em->persist($file); $em->flush(); $imageId = $file->getId(); $arraydecode = json_encode($imageId); $response = new Response($arraydecode); $response->headers->set('Content-Type', 'application/json'); } } return $response; }
public function recoverydownloadAction(File $file) { $nom = $file->getPathFile(); // commencer compression $dirZip = $this->get('kernel')->getRootDir() . '/../web/' . $nom; // echo $dirZip; // exit(); $this->Zip($dirZip, './doc.zip'); // proposer telechargement header('Content-Transfer-Encoding: binary'); //Transfert en binaire (fichier). header('Content-Disposition: attachment; filename="doc.zip"'); //Nom du fichier. header('Content-Length: ' . filesize('doc.zip')); //Taille du fichier. readfile('doc.zip'); // fin telechargement // fin compression // suppression zip $fileZipToDelete = $this->get('kernel')->getRootDir() . '/../web/doc.zip'; unlink($fileZipToDelete); return $this->redirect($this->generateUrl('innova_platin_page_recuperer_document')); }