2013-03-08 32 views
0

在我的蛋糕的看法,我有以下形式:CakePHP中,如何上传图片

<form enctype="multipart/form-data" action="<?php echo $this->base; ?>/reviews/upload/" method="post" target="_blank"> 
<input type="file" id="file" name="file" /> 
<input type="submit" /> 
</form> 

在ReviewsController,在上传()方法有:

public function upload() { 
    var_dump($this->request->data);   
} 

但它总是空!我已经尝试过“this-> request”,“this-> data”,但它总是空的。 我在做什么错?

回答

4

尝试做蛋糕的方式,

echo $this->Form->create("Review", array("action" => "upload", "type" => "file")); 
    echo $this->Form->input("my-file", array("type" => "file")); 
echo $this->Form->end(); 

在你的评论控制器

public function upload() { 
    debug($this->request->data);  
} 

使用调试过的var_dump和print_r的的优势是调试可以在生产模式应用广泛通过设置降低关闭core.php中调试级别为0

+0

它的工作,谢谢! – 2013-03-08 10:17:20

+0

@BarthZalewski如果它的工作,你可以标记为未来谷歌公认的答案 – 2013-03-08 10:22:12

0

尝试将输入的名称更改为somethinge,然后是文件。以前有问题!

+0

仍然没有。有谁知道我如何在控制器中读取我的POST数据? – 2013-03-08 09:55:35