Hello
I am saving docx file as binary to database BLOB. I would like to also save the content of the file to be able to search for phrases in doc without opening it. I found PHP code to read docx file and it works. Now - how to incorporate this while saving form on which I have file input field?
The form has string fields and on file input field ‘cv’.
Here is my controller code:
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Candidate']))
{
if($_FILES['Candidate']['name']['cv']=='')
{
$model->name=$_POST['Candidate']['name'];
$model->surname=$_POST['Candidate']['surname'];
$model->id_candidate_avail=$_POST['Candidate']['id_candidate_avail'];
$model->id_candidate_src=$_POST['Candidate']['id_candidate_src'];
$model->id_sector=$_POST['Candidate']['id_sector'];
$model->id_subsector=$_POST['Candidate']['id_subsector'];
$model->address_main=$_POST['Candidate']['address_main'];
$model->address_code=$_POST['Candidate']['address_code'];
$model->address_city=$_POST['Candidate']['address_city'];
$model->mobile=$_POST['Candidate']['mobile'];
$model->phone=$_POST['Candidate']['phone'];
$model->email=$_POST['Candidate']['email'];
$model->comments=$_POST['Candidate']['comments'];
$model->save(true,array('name','surname','id_candidate_avail','id_candidate_src','id_sector','id_subsector','address_main','address_code','address_city','address_region','mobile','phone','email','comments'));
}
else
{
$model->attributes=$_POST['Candidate'];
$model->save();
}
$file=CUploadedFile::getInstance($model,'cv');
if($file)
{
if($_FILES['Candidate']['name']['cv']!=''){
$cv_file_content=substr(file_get_contents($file->tempName),0,200);
$cv_file_type=$file->type;
$cv_file_size=$file->size;
$cv=$file->name;
}
}
$this->redirect(array('view','id'=>$model->id));
}
$this->render('update',array(
'model'=>$model,
));
}
It works, it saves docs to database, it updates them with new files.
Now how to add mentioned earlier code to read docx before saving/updating and save it to new text field in DB?
Thanks in advance