我发现a tutorial显示了如何上传文件并将其作为blob存储在DB中。这是我在FilesController
中的代码:
$zip_file=$this->data['File']['zip'];
$fileData = fread(fopen($zip_file['tmp_name'], "r"), $zip_file['size']);
$this->data['File']['zip'] = $fileData;
$this->File->save($this->data);
执行时出现此错误:
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'
SQL Query: INSERT INTO `my_db`.`files` (`task_id`, `zip`) VALUES (5, Array)
显然这是问题,因为$ zip是一个数组。怎么解决?
DEBUG:
var_dump($this->data['File']);
:
array (size=2)
'task_id' => string '5' (length=1)
'zip' =>
array (size=5)
'name' => string 'Vaja1.zip' (length=9)
'type' => string 'application/x-zip-compressed' (length=28)
'tmp_name' => string 'C:\wamp\tmp\php50B9.tmp' (length=23)
'error' => int 0
'size' => int 847624