getDataSource(); $dataSource->begin(); $this->id = $data["AppUser"]['id']; $this->User->id = $data["AppUser"]['user_id']; $filename = $this->id . "_-profil.". pathinfo($data[$this->alias]['avatar']['name'], PATHINFO_EXTENSION); $filename = WWW_ROOT . $this->uploadDir . DS . $filename; if(file_exists($filename)){ chmod($filename,0755); //Change the file permissions if allowed unlink($filename); //remove the file } if (!move_uploaded_file($data[$this->alias]['avatar']['tmp_name'], $filename)) { $result = false; } else { $result = $this->saveField('avatar', str_replace(DS, "/", str_replace(WWW_ROOT.$this->uploadDir.DS, "", $filename) )); } if ($result) { $dataSource->commit(); return true; } else { $dataSource->rollback(); } return false; } public $validate = array( 'id' => array( 'naturalNumber' => array( 'rule' => array('naturalNumber'), //'message' => 'Your custom message here', //'allowEmpty' => false, //'required' => false, //'last' => false, // Stop validation after this rule //'on' => 'create', // Limit validation to 'create' or 'update' operations ), ), 'user_id' => array( 'numeric' => array( 'rule' => array('numeric'), //'message' => 'Your custom message here', //'allowEmpty' => false, //'required' => false, //'last' => false, // Stop validation after this rule //'on' => 'create', // Limit validation to 'create' or 'update' operations ), ), 'take_systemwide' => array( 'boolean' => array( 'rule' => array('boolean'), //'message' => 'Your custom message here', //'allowEmpty' => false, //'required' => false, //'last' => false, // Stop validation after this rule //'on' => 'create', // Limit validation to 'create' or 'update' operations ), ), ); public $belongsTo = array( 'User' => array( 'className' => 'User', 'foreignKey' => 'user_id' ), 'Mannerofaddress' => array( 'className' => 'Mannerofaddress', 'foreignKey' => 'mannerofaddress_id', 'conditions' => '', 'fields' => '', 'order' => '' ) ); }