Advertisement
Guest User

Controller

a guest
Sep 23rd, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Zend Framework (http://framework.zend.com/)
  5. *
  6. * @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
  7. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  8. * @license http://framework.zend.com/license/new-bsd New BSD License
  9. */
  10.  
  11. namespace Application\Controller;
  12.  
  13. use Zend\Mvc\Controller\AbstractActionController;
  14. use Application\Form\UploadForm;
  15.  
  16. class FileController extends AbstractActionController {
  17.  
  18. public function indexAction() {
  19. $form = new UploadForm('upload-form');
  20. $tempFile = null;
  21.  
  22. $prg = $this->fileprg($form);
  23. if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
  24. return $prg; // Return PRG redirect response
  25. } elseif (is_array($prg)) {
  26. if ($form->isValid()) {
  27. $data = $form->getData();
  28. // Form is valid, save the form!
  29. return $this->redirect()->toRoute('upload-form/success');
  30. } else {
  31. // Form not valid, but file uploads might be valid...
  32. // Get the temporary file information to show the user in the view
  33. $fileErrors = $form->get('image-file')->getMessages();
  34. if (empty($fileErrors)) {
  35. $tempFile = $form->get('image-file')->getValue();
  36. }
  37. }
  38. }
  39.  
  40. return array(
  41. 'form' => $form,
  42. 'tempFile' => $tempFile,
  43. );
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement