public function executeUpdateFoto() { $user_id = $this->getContext()->getUser()->getAttribute('user_id', null, 'bo'); $applicant = TestApplicantPeer::retrieveByPk($user_id); $this->forward404Unless($applicant); $applicant_detail = $applicant->getTestApplicantDetail(); // save photo $photo_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; if ($this->hasRequestParameter('photoFile') && $this->getRequestParameter('photoFile') != '' && $this->getRequestParameter('photoFile') != null) { // get photo content $photo_file = $photo_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('photoFile'); $content = file_get_contents($photo_file); $im = imagecreatefromstring($content); list($w, $h) = getimagesize($photo_file); // generate photo $photo = imagecreatetruecolor(150, 195); imagecopyresized($photo, $im, 0, 0, 0, 0, 150, 195, $w, $h); // generate thumbnail $thumb = imagecreatetruecolor(100, 130); imagecopyresized($thumb, $im, 0, 0, 0, 0, 100, 130, $w, $h); // get photo record $c = new Criteria(); $c->add(TestApplicantPhotoPeer::TEST_APPLICANT_ID, $applicant->getId()); $applicant_photo = TestApplicantPhotoPeer::doSelectOne($c); if ($applicant_photo == null) { $applicant_photo = new TestApplicantPhoto(); $applicant_photo->setTestApplicant($applicant); } // save photo imagepng($photo, $photo_file); $applicant_photo->setPhoto(base64_encode(file_get_contents($photo_file))); imagepng($thumb, $photo_file); $applicant_photo->setThumbnail(base64_encode(file_get_contents($photo_file))); $applicant_photo->save(); unlink($photo_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('photoFile')); } return $this->redirect('auth/index'); }
public function addTestApplicantPhoto(TestApplicantPhoto $l) { $this->collTestApplicantPhotos[] = $l; $l->setTestApplicant($this); }