public function executeRun() { $this->applicant = $this->applicant; $this->error = false; $this->upload = false; $tmp_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; //$fileRenameTo = $this->getRequestParameter('fileRenameTo'); $fileRenameTo = 'test'; $fileName = $this->getRequest()->getFileName('photo'); $filePath = $this->getRequest()->getFilePath('photo'); $this->orig_filename = $fileName; if ($fileName != null && $fileName != '') { $this->upload = true; $exif_type = exif_imagetype($filePath); if ($exif_type == IMAGETYPE_GIF || $exif_type == IMAGETYPE_JPEG || $exif_type == IMAGETYPE_PNG) { $content = file_get_contents($filePath); $im = imagecreatefromstring($content); list($w, $h) = getimagesize($filePath); // 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); $c = new Criteria(); $c->add(TestApplicantPhotoPeer::TEST_APPLICANT_ID, $this->applicant->getId()); $applicant_photo = TestApplicantPhotoPeer::doSelectOne($c); if ($applicant_photo == null) { $applicant_photo = new TestApplicantPhoto(); $applicant_photo->setTestApplicantId($this->applicant->getId()); } // save photo imagepng($photo, $filePath); $applicant_photo->setPhoto(base64_encode(file_get_contents($filePath))); imagepng($thumb, $filePath); $applicant_photo->setThumbnail(base64_encode(file_get_contents($filePath))); try { $applicant_photo->save(); } catch (exception $e) { $this->error = true; } } else { $this->error = true; } } }
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'); }