0

I am pretty new to cakephp, I have an uploader form and would like to pass all of the data using POST to the controller and model so that it will save to the database. So far there are no cakephp errors occuring but no data is being passed.

Controller Code:

<?php class Controller extends AppController {

  public function add() {
    if ($this->request->is('post')) {
        $this->File->create();
        if ($this->File->save($this->request->data)) {
            $this->Session->setFlash(__('Your file has been liberated :)'));
            $this->redirect($this->referer());
        } else {
            $this->Session->setFlash(__('Something went wrong!'));
        }
    }
}
}?>

View Code:

<?php echo $this->Form->create('File'); ?>
<input type="uploader" name="selected-file" style="visibility: hidden;"/>
<?php echo $this->Form->end('Finish'); ?>

Model Code:

<?php class File extends AppModel {}
?>
4

1 に答える 1

0

そこにある入力仕様を確認してくださいtype。属性に「uploader」値がないことを確認してください。多分あなたは意味しtype="file"ます。

また、ファイルをアップロードしたい場合は、

echo $this->Form->create('File', array('type' => 'file')); 

これにより、正しい enctype 属性が生成されますenctype="multipart/form-data"。POST でファイルを送信する場合は、このような enctype が必要です。

また、ファイル入力フィールドを非表示にする必要がある style:style="visibility: hidden;"を使用するため、おそらくいくつかのフラッシュ アップローダーまたは ajax を使用しますが、これはコードでは示されません。より多くのコードを提供していただければ、より具体的なヘルプを提供できます。

反論の質問: コードをどのようにデバッグしますか?

于 2013-07-17T07:09:48.983 に答える