0
Hallo ich bin ein Anfänger in CakePHP 3.0 mein Ich habe ein Problem, wird es nicht in der Datenbank speichern.Mehrere hochladen in CakePHP 3.0
Controller:
public function add() {
$myTable = TableRegistry::get('Files');
$data = $this->request->getData();
$file = $myTable->newEntities($data);
if ($this->request->is('post')) {
foreach ($file as $key => $val) {
$val['user_id'] = $this->Auth->user('id');
$val['filename'] = $_FILES['photo']['name'];
$val['file_location'] = '../uploads/files/';
$val['file_type'] = $_FILES['photo']['type'];
$val['file_size'] = $_FILES['photo']['size'];
$val['file_status'] = 'Active';
$val['created'] = date("Y-m-d H:i:s");
$val['modified'] = date("Y-m-d H:i:s");
if($myTable->save($val)) {
$this->Flash->success(__('File has been uploaded and inserted successfully.'));
} else {
$this->Flash->error(__('File not upload!'));
}
}
}
}
kann mir jemand helfen, mein Problem zu festen, folgte ich die Dokumentation in CakePHP, aber es scheint nicht funktioniert.
Aufrufe:
<?= $this->Form->create(null, ['type' => 'file', 'url' => ['controller' => 'Files', 'action' => 'add']]) ?>
echo $this->Form->input('photo[]', ['type' => 'file','multiple' => 'true','label' => 'Upload Multiple Photos']);
Dies ist meine Datenbankstruktur:
CREATE TABLE `files` (
`id` int(8) NOT NULL,
`user_id` varchar(100) NOT NULL,
`filename` varchar(100) NOT NULL,
`file_location` varchar(1000) NOT NULL,
`file_type` varchar(100) NOT NULL,
`file_size` varchar(100) NOT NULL,
`file_status` varchar(100) NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
es mir eine Fehler undefinierte Art, Größe und Namen –
Könnten Sie bitte posten, dass pr ($ _ FILES) gibt ;sterben; Drucke. –
ich ändere meinen Code ich benutze für Schleife, aber speichern funktioniert nicht. dann ist meine Speicherfunktion das $ table = TableRegistry :: get ('Files'); $ entities = $ table-> newEntities ($ file); $ table-> saveMany ($ entities); aber es funktioniert nicht –