fork download
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use AppBundle\Type\UploadType;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  8. use Symfony\Component\HttpFoundation\File\UploadedFile;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12.  
  13. class FileController extends Controller
  14. {
  15. /**
  16.   * @Route("/upload")
  17.   */
  18. public function uploadAction(Request $request)
  19. {
  20. $form = $this->createForm(UploadType::class);
  21.  
  22. $form->handleRequest($request);
  23. if ($form->isSubmitted()) {
  24. /** @var UploadedFile $uploadedFile */
  25. $uploadedFile = $form['file']->getData();
  26.  
  27. $file = $this->get('file_uploader')->upload(
  28. $uploadedFile,
  29. $uploadedFile->getClientOriginalName()
  30. );
  31.  
  32. return new RedirectResponse($this->generateUrl('file', ['id' => $file->getId()]));
  33. }
  34.  
  35. return $this->render('upload.html.twig', [
  36. 'form' => $form->createView(),
  37. ]);
  38. }
  39.  
  40. /**
  41.   * @Route("/file/{id}", name="file", requirements={"id": "\d+"})
  42.   */
  43. public function getOneAction(Request $request, $id)
  44. {
  45. $file = $this->getDoctrine()->getRepository('AppBundle:File')->find($id);
  46. if (!$file) {
  47. throw new NotFoundHttpException();
  48. }
  49.  
  50. return $this->render('file.html.twig', [
  51. 'file' => $file,
  52. ]);
  53. }
  54. }
Runtime error #stdin #stdout #stderr 0s 82880KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Class 'Symfony\Bundle\FrameworkBundle\Controller\Controller' not found in /home/YbMC5I/prog.php on line 13