dopr25398 2013-03-08 09:50
浏览 42
已采纳

cakephp,如何上传图片

In my cake view, I have the following form:

<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>

In the ReviewsController, in the upload() method there is:

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

but it's always empty! I already tried "this->request", "this->data" but it's always empty. What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • dongtang5229 2013-03-08 09:58
    关注

    Try doing it cake way,

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

    In your reviews controller

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

    Using debug over var_dump and print_r as advantage that debug can be turned off in production mode application wide by setting lowering the debug level to 0 in core.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 html5+css有人可以帮吗?
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?