我的表格是
<?php echo $this->Form->create('User', array('type' => 'file')); ?>
。 。 。 。
<?php
echo $this->Form->input('Profile-Picture', array('type' => 'file','name' => 'data[User][profileimg]')); ?>
<?php echo $this->Form->end(('Submit')); ?>
在控制器功能上,它显示数据数组,如:
Array
(
[User] => Array
(
[id] => 22
[fname] => Mehr
[lname] => Jamil Rana
[username] => Mehr Rana
[email] => mehreen@abc.com
[password] => 619016456d0023d6a57b3f3551c474bf
[Retype password] =>
[term_approved ] => Array
(
[0] => 1
)
[profileimg] => thumbthumbnailofslide1.png
)
)
答案 0 :(得分:0)
<?php
echo $this->Form->create('User',array('enctype' => 'multipart/form-data'));
echo $this->Form->input('profileimg',array('type' => 'file','label'=>'Profile-Picture'));
echo $this->Form->end(('Submit'));
答案 1 :(得分:0)
由于HTML本身的限制,无法将默认值放入“file”类型的输入字段中。每次显示表单时,里面的值都将为空。
http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-file-inputs
答案 2 :(得分:-1)
当你发出POST请求时,你必须以某种方式对构成请求主体的数据进行编码,对于$ _FILES你需要添加multipart / form-data编码。
试试这个
<?php echo $this->Form->create('User', array('enctype' => 'multipart/form-data'));
echo $this->Form->input('Profile-Picture', array('type' => 'file','name' =>'data[User][profileimg]'));
echo $this->Form->end(('Submit'));
?>
答案 3 :(得分:-1)
对文件使用encrypt选项,在输入标签中提到输入是文件类型。