以下验证在我的模型CakePHP的上传图片 - 无法确定MIME类型
'image' => array(
'uploadErrror' => array(
'rule' => 'uploadError',
'message' => 'The image upload failed.',
'allowEmpty'=> True
),
'mimeType' => array(
'rule' => array('mimeType',array('image/gif','image/png','image/jpeg')),
'message' => 'Please only upload images (gif, png, jpg).',
'allowEmpty' => true
),
'fileSize'=> array(
'rule' => array('fileSize', '<=', '1MB'),
'message' => 'Image must be less than 1MB.',
'allowEmpty' => true
),
'processImageUpload' => array(
'rule' => 'processImageUpload',
'message' => 'Unable to process image upload.',
'allowEmpty'=> true
) )
public function processImageUpload($check = array()){
if(!is_uploaded_file($check['image']['tmp_name']))
{
return FALSE;
}
$targetdir = WWW_ROOT . 'img' . DS . 'uploads' . DS . $check['image']['name'];
if(!move_uploaded_file($check['image']['tmp_name'],$targetdir))
{
return false;
}
$this->data[$this->alias]['image'] = 'uploads' . DS . $check['image']['name'];
return true;
}
正在做我收到的错误是下面的,我也启用了调试2但没有提供进一步的澄清。
无法确定mimetype。
我已经尝试取消注释
延长= php_fileinfo.dll
并重新启动WAMPServer充分,但它仍然没有奏效。
另外,在控制器类我有下面的代码添加
public function add() {
if ($this->request->is('post')) {
$this->Image->create();
$data = $this->request->data['Image'];
if (!$data['image']['name'])
{
$this->Session->setFlash(__('There was no image provided.'));
}
if ($this->Image->save($data)) {
$this->Session->setFlash(__('The image has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The image could not be saved. Please, try again.'));
}
}
}
添加视图代码
<?php echo $this->Form->create('Image',array('type'=>'file')); ?>
<fieldset>
<legend><?php echo __('Add Image'); ?></legend>
<?php
echo $this->Form->input('description');
echo $this->Form->input('image',array('type'=>'file'));
echo $this->Form->input('property_id');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
任何建议,将不胜感激。
真的,我确实有一个错误,但它并没有解决问题sadly.But感谢帮助无论如何 – Enzero
你也可以添加'image/jpg'到允许的文件类型列表。这似乎并不会解决这个问题。 – Kluny
感谢您的建议。 – Enzero