/** * Renvoit le fichier pour une pièce justificative * donnée et un utilisateur donné. * * @param integer $type_file de pièce justificative * @param User $user instance d'un "User" qui possède le fichier que l'on souhaite télécharger * @return Response renvoit la réponse HTTP. */ private function download($type_file, User $user) { if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { throw $this->createAccessDeniedException(); } // ensure the type file is in the accepted range if (!preg_match('/^[1-6]$/', $type_file)) { throw $this->createAccessDeniedException(); } $paths = array(User::TYPE_DOMICILE => $user->getAbsolutePathDomicile(), User::TYPE_PRESTATIONS => $user->getAbsolutePathPrestations(), User::TYPE_SALAIRE1 => $user->getAbsolutePathSalaire1(), User::TYPE_SALAIRE2 => $user->getAbsolutePathSalaire2(), User::TYPE_SALAIRE3 => $user->getAbsolutePathSalaire3(), User::TYPE_IMPOTS => $user->getAbsolutePathImpot()); $ext = strtolower(pathinfo($paths[$type_file], PATHINFO_EXTENSION)); $content_types = array('pdf' => 'application/pdf', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png'); // check the extension if (!array_key_exists($ext, $content_types)) { throw $this->createAccessDeniedException(); } $new_filenames = array(User::TYPE_DOMICILE => "justif_domicile." . $ext, User::TYPE_PRESTATIONS => "justif_prestations." . $ext, User::TYPE_SALAIRE1 => "justif_salaire_1." . $ext, User::TYPE_SALAIRE2 => "justif_salaire_2." . $ext, User::TYPE_SALAIRE3 => "justif_salaire_3." . $ext, User::TYPE_IMPOTS => "justif_impots." . $ext); // build the HTTP response $response = new Response(); $response->headers->set('Cache-Control', 'no-cache'); $response->headers->set('Content-Type', $content_types[$ext]); $response->headers->set('Content-Length', filesize($paths[$type_file])); $response->headers->set('Content-Disposition', 'inline; filename="' . $new_filenames[$type_file] . '"'); $response->setContent(file_get_contents($paths[$type_file])); return $response; }
/** * @param $user * @param $nbChildrenVoyageInscrits * @return array */ private function getFiles(User $user, $nbChildrenVoyageInscrits) { $filesArray = array(); $filesArray[User::TYPE_PRESTATIONS] = array('libelle_justif' => 'Justificatif de CAF', 'exists' => is_file($user->getAbsolutePathPrestations())); $filesArray[User::TYPE_DOMICILE] = array('libelle_justif' => 'Justificatif de domicile', 'exists' => is_file($user->getAbsolutePathDomicile())); $filesArray[User::TYPE_SALAIRE1] = array('libelle_justif' => 'Justificatif de salaire 1', 'exists' => is_file($user->getAbsolutePathSalaire1())); $filesArray[User::TYPE_SALAIRE2] = array('libelle_justif' => 'Justificatif de salaire 2', 'exists' => is_file($user->getAbsolutePathSalaire2())); $filesArray[User::TYPE_SALAIRE3] = array('libelle_justif' => 'Justificatif de salaire 3', 'exists' => is_file($user->getAbsolutePathSalaire3())); if ($nbChildrenVoyageInscrits) { $filesArray[User::TYPE_IMPOTS] = array('libelle_justif' => "Justificatif avis d'imposition", 'exists' => is_file($user->getAbsolutePathImpot())); } return $filesArray; }