0

View(edit) はすべてのフィールドを正しく表示し、変更されたフィールドを更新していますが、ファイルを処理できません。つまり、新しいファイルがアップロードされた場合、古いファイル名を保持する必要がない場合は更新する必要があります。

コントローラ:

public function edit($id = null) {
    if (!$id) {
        throw new NotFoundException(__('Invalid post'));
    }

    $post = $this->Student->findById($id);
    if (!$post) {
        throw new NotFoundException(__('Invalid post'));
    }

    if ($this->request->is('post') || $this->request->is('put')) {
        $this->Student->id = $id;
        if ($this->Student->save($this->request->data)) {
            $this->Session->setFlash(__('Your post has been updated.'));
            return $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Unable to update your post.'));
    }

    if (!$this->request->data) {
        $this->request->data = $post;
    }
    }

意見:

<h1>Edit student record</h1>
<?php   
    echo $this->Form->create('Student',array('type'=>'file'));
    echo $this->Form->input('first_name'); 
    echo $this->Form->input('current_address');
    echo 'resume'.$this->Form->file('resume');
    echo $this->Form->input ('comments');
    echo 'photo'.$this->Form->file('photo'); 
    echo $this->Form->input('id', array('type' => 'hidden'));
    //echo $this->Form->input('resume', array('type' => 'hidden'));
    //echo $this->Form->input('photo', array('type' => 'hidden'));
    echo $this->Form->end('Save Post');

誰かがアップロードの処理方法を教えてもらえますか

4

1 に答える 1