When uploading files you usually get an array created for the field. For example in the case where the model is Document and field is submittedfile:
$this->request->data['Document']['submittedfile'] = array(
'name' => 'conference_schedule.pdf',
'type' => 'application/pdf',
'tmp_name' => 'C:/WINDOWS/TEMP/php1EE.tmp',
'error' => 0,
'size' => 41737,
);
The array cannot be saved to the DB because the field cannot save the 'submittedfile' array to the DB 'submittedfile' column. However I only need the name section of the above array in the submittedfile field of the DB. Tried a number of ways here are two:
1 Turning the submittedfile from array to string in the Controller Method before calling the save method in Controller Methdod. (Issue could not use cakePHP validate for fileSize and uploadError as they require ['tmp_name'] to work.)
public function addDocument(){
$this->request->data['Document']['submittedfile'] = $this->request->data['Document']['submittedfile']['name'];
$this->Document->save($this->request->data);}
2 Turning the submittedfile from array to string in the beforeSave Callback Method before calling the save method in Controller Method. (Issue is that I get Error Illegal string offset 'name')
public function beforeSave($options = array()){
$this->data['Document']['submittedfile'] = $this->data['Document']['submittedfile']['name'];}
Any answers for saving uploaded file type arrays to DB?