I found a tutorial showing how to upload a file and store it in DB as blob. This is my code in 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);
getting this error upon execution:
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)
Obviously it's the problem because $zip is an array. How to solve it?
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
Alright, found an answer - in short:
I had to replace every $this->data
with $this->request->data
and now it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.