datei in cakephp hochladen 2.3

Ich bin neu in cakephp und ich versuche mit cakephp 2.3 einen einfachen Datei-Upload zu erstellen. Hier ist mein Controller

public function add() {
    if ($this->request->is('post')) {
        $this->Post->create();
           $filename = WWW_ROOT. DS . 'documents'.DS.$this->data['posts']['doc_file']['name']; 
           move_uploaded_file($this->data['posts']['doc_file']['tmp_name'],$filename);  


        if ($this->Post->save($this->request->data)) {
            $this->Session->setFlash('Your post has been saved.');
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash('Unable to add your post.');
        }
     }
 }

und meine add.ctp

echo $this->Form->create('Post');
echo $this->Form->input('firstname');
echo $this->Form->input('lastname');
echo $this->Form->input('keywords');
echo $this->Form->create('Post', array( 'type' => 'file'));
echo $this->Form->input('doc_file',array( 'type' => 'file'));
echo $this->Form->end('Submit')

es speichert vorname, nachname, schlüsselwörter und den namen der datei in der datenbank, aber die datei, die ich in app / webroot / documents speichern möchte, wird nicht gespeichert, kann mir jemand helfen? Vielen Dank

Aktualisieren

thaJeztah ich habe wie du gesagt hast, aber es gibt einige Fehler hier ist Controller, wenn ich mich nicht irre

public function add() {
     if ($this->request->is('post')) {
         $this->Post->create();
            $filename = WWW_ROOT. DS . 'documents'.DS.$this->request->data['Post']['doc_file']['name']; 
           move_uploaded_file($this->data['posts']['doc_file']['tmp_name'],$filename);



         if ($this->Post->save($this->request->data)) {
             $this->Session->setFlash('Your post has been saved.');
             $this->redirect(array('action' => 'index'));
         } else {
            $this->Session->setFlash('Unable to add your post.');
         }
     }

 }

und meine add.ctp

 echo $this->Form->create('Post', array( 'type' => 'file'));
 echo $this->Form->input('firstname'); echo $this->Form->input('lastname');
 echo $this->Form->input('keywords');
 echo $this->Form->input('doc_file',array( 'type' => 'file'));
 echo $this->Form->end('Submit') 

und die fehler sind

Hinweis (8): Konvertierung von Array in String [CORE \ Cake \ Model \ Datasource \ DboSource.php, Zeile 1005]

Datenbankfehler Fehler: SQLSTATE [42S22]: Spalte nicht gefunden: 1054 Unbekannte Spalte 'Array' in 'Feldliste'

SQL-Abfrage: INSERT INTO first.posts (Vorname, Nachname, Schlüsselwörter, doc_file) VALUES ('dfg', 'cbhcfb', 'dfdbd', Array)

und Victor, ich habe deine Version auch gemacht, es funktioniert auch nicht.

Antworten auf die Frage(4)

Ihre Antwort auf die Frage