以下驗證在我的模型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