public function applyAction()
 {
     $form = new ApplicationForm();
     $form->get('submit')->setValue('Apply Now!');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $application = new Application();
         $form->setInputFilter($application->getInputFilter());
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($post);
         if ($form->isValid()) {
             $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
             $application->exchangeArray($data);
             $size = new Size(['min' => 20, 'max' => 200000]);
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             $adapter->setValidators([$size], $application->getProfilePic());
             $adapter->setValidators([$size], $application->getBasePic());
             if (!$adapter->isValid()) {
                 $errors = $adapter->getMessages();
                 return ['form' => $form, 'errors' => $errors];
             }
             $path = '/applications/' . $application->getTag() . '/';
             $prefix = getcwd() . '/public';
             if (!file_exists($prefix . '/applications/')) {
                 mkdir($prefix . '/applications/');
             }
             if (!file_exists($prefix . $path)) {
                 mkdir($prefix . $path);
             }
             $basePic = $application->getBasePic();
             $ending = pathinfo($basePic['name'], PATHINFO_EXTENSION);
             $application->setBasePic($path . 'basepic.' . $ending);
             $basePicFile = file_get_contents($basePic['tmp_name']);
             file_put_contents($prefix . $application->getBasePic(), $basePicFile);
             $profilePic = $application->getProfilePic();
             $ending = pathinfo($profilePic['name'], PATHINFO_EXTENSION);
             $application->setProfilePic($path . 'profilepic.' . $ending);
             $profilePicFile = file_get_contents($profilePic['tmp_name']);
             file_put_contents($prefix . $application->getProfilePic(), $profilePicFile);
             try {
                 $this->getApplicationTable()->saveApplication($application);
             } catch (\Exception $e) {
                 return $this->redirect()->toRoute('applynow', ['action' => 'applyfailed']);
             }
             $id = $this->getApplicationTable()->getLastInsertedId();
             return $this->redirect()->toRoute('applynow', ['action' => 'applysuccess', 'id' => $id]);
         } else {
             $errors = $form->getMessages();
             return ['form' => $form, 'errors' => $errors];
         }
     }
     return ['form' => $form];
 }