Created
August 10, 2018 18:32
-
-
Save NandoKstroNet/02d83d2f81b83f00dbd80235a0b8b548 to your computer and use it in GitHub Desktop.
Método upload do Controller UploadController, projeto Symfony 4. Código criado na série da CEL sobre Upload de Arquivos com Symfony 4 em youtube.com/CodeExpertsLearning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... Controller completo: https://github.com/CodeExpertsLearning/serie-symfony-4-upload-de-arquivos/blob/master/src/Controller/UploadController.php | |
/** | |
* @Route("/upload", name="upload", methods="POST") | |
*/ | |
public function upload(Request $request) | |
{ | |
try { | |
$files = $request->files->get('file'); | |
foreach ($files as $f) { | |
$newName = md5($f->getClientOriginalName()) . uniqid() . time() . '.' . $f->guessExtension(); | |
$f->move($this->getParameter('upload_folder'), $newName); | |
} | |
$this->addFlash('success', 'Upload realizado com sucesso!'); | |
return $this->redirectToRoute('home_upload'); | |
} catch (\Exception $e) { | |
$this->addFlash('error', 'Erro ao realizar upload: ' . $e->getMessage()); | |
return $this->redirectToRoute('home_upload'); | |
} | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment