I am trying to Upload a photo for one of the models and when i am going to the edit mode. It still asks me to upload the photo when the user only wants to edit the text related to that record. Below is my Validation Rules.
'display_photo' => array(
'uploadError' => array(
'rule' => array('uploadError'),
'message' => 'Please select a Photo.',
'allowEmpty' => true,
),
'mimeType' => array(
'rule' => array('mimeType', array('image/gif', 'image/png', 'image/jpg', 'image/jpeg')),
'message' => 'Please only upload images (gif, png, jpg).',
'allowEmpty' => true,
),
'fileSize' => array(
'rule' => array('fileSize', '<=', '5MB'),
'message' => 'Photo must be less than 5MB.',
'allowEmpty' => true,
),
'photoUpload' => array(
'rule' => array('photoUpload'),
'message' => 'Unable to process Photo upload.',
'allowEmpty' => true,
),
),
Upload Function
public function photoUpload($check = array()) {
if (!is_uploaded_file($check['display_photo']['tmp_name'])) {
return false;
}
if (!move_uploaded_file($check['display_photo']['tmp_name'], WWW_ROOT . 'img' . DS .
'portfolios' . DS . $this->data[$this->alias]['slug'].".".pathinfo($check['display_photo']['name'], PATHINFO_EXTENSION))) {
return false;
}
$this->data[$this->alias]['display_photo'] = $this->data[$this->alias]['slug'].".".pathinfo($check['display_photo']['name'], PATHINFO_EXTENSION);
return true;
}