当我创建一个项目时,图像上传验证工作正常,但当我编辑项目时,它总是要求我再次上传文件。使用firebug,我检查了img_upload输入,它的值是"Lighthouse.jpg“。
我该如何克服这个问题呢?
在我的模型验证下面
'img_upload' = array(
'extension' => array(
'rule' => array('extension', array('png','jpg','jpeg')),
'message' => "Only png,jpg,jpeg Files Allowed",
)
);
下面是我的html代码:
echo $this->Form->create('Project',array('type'=>'file'));
echo $this->Form->input('img_upload');
echo $this->Form->end('Submit');
发布于 2015-11-26 09:10:44
您当前的规则是将文件上载设置为必填字段,因此如果文件在编辑时未上载,将会出错。尝试将'allowEmpty' => true
添加到您的验证规则以防止需要它:-
'img_upload' = array(
'extension' => array(
'rule' => array('extension', array('png','jpg','jpeg')),
'message' => "Only png,jpg,jpeg Files Allowed",
'allowEmpty' => true,
)
);
发布于 2015-11-26 15:10:53
您好,尝试将您的输入代码从
echo $this->Form->input('img_upload');
到这个
echo $this->Form->input('img_upload','type'=>'file');
https://stackoverflow.com/questions/33933507
复制相似问题