public function actionUpload() { $candidateID = intval($_POST['candidateID']); $Candidate = Candidates::findOne($candidateID); if (!$Candidate) { echo 0; die; } $finalDir = '/home/ubuntu/workspace/basic/uploads/' . $Candidate->id; if (!is_dir($finalDir)) { mkdir($finalDir); } $CandidatesFiles = new CandidatesFiles(); $CandidatesFiles->candidate_id = $Candidate->id; $CandidatesFiles->original_filename = basename($_FILES['uploadedFile']['name']); $CandidatesFiles->server_filename = time() . "_" . $CandidatesFiles->original_filename; if (move_uploaded_file($_FILES['uploadedFile']['tmp_name'], $finalDir . "/" . $CandidatesFiles->server_filename)) { // HP Store object $fileUrl = Url::to('@web/uploads/' . $Candidate->id . '/' . $CandidatesFiles->server_filename, true); $CandidatesFiles->hp_reference_id = Yii::$app->HpApi->storeObject($fileUrl); $CandidatesFiles->save(); // Resumes object $Resumes = new Resumes(); $Resumes->candidate_file_id = $CandidatesFiles->id; // HP OCR $Resumes->hp_job_id = Yii::$app->HpApi->ocrDocument($CandidatesFiles->hp_reference_id); $Resumes->save(); // Resumes faces object $ResumesFaces = new ResumesFaces(); $ResumesFaces->resume_id = $Resumes->id; // HP Face Detection $ResumesFaces->hp_job_id = Yii::$app->HpApi->faceDetection($CandidatesFiles->hp_reference_id); $ResumesFaces->save(); echo 1; } else { echo 0; } }
public function getCandidatesFiles() { return $this->hasOne(CandidatesFiles::className(), ['id' => 'candidate_file_id']); }