我找到了一个教程,展示了如何上传文件并将其作为 blob 存储在数据库中。这是我的代码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 是一个数组。如何解决?
调试:
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