Created
February 19, 2018 02:41
-
-
Save anonymous/f9f773d40f373845ec1ee16696206687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function register() | |
{ | |
$user = $this->Users->newEntity(); | |
$value = $this->request->getData('username'); | |
if($this->request->is('post')) { | |
$image_name = $this->request->data['profile_pic']['name']; | |
$image_tmp = $this->request->data['profile_pic']['tmp_name']; | |
$user_input_folder = WWW_ROOT.'img'.DS.'users'.DS.$value.DS; | |
$destination = $user_input_folder.$image_name; | |
if (!file_exists($user_input_folder)) { //Checks file or folder exist or not | |
if(mkdir($user_input_folder, 0777, true)){ | |
$oldMask = umask(0); | |
chmod($user_input_folder, 0777); | |
umask($oldMask); | |
$this->request->data['destination'] = $destination;/// to store to destination field | |
move_uploaded_file($image_tmp, $destination); | |
} else { | |
pr("User input contains at least one illegal character, so can't create folder.");die; | |
} | |
} | |
$user= $this->Users->patchEntity($user,$this->request->getData()); | |
if($this->Users->save($user)) { | |
$this->Flash->success(__('User successfuly added.')); | |
return $this->redirect(['action' => 'login']); | |
} else { | |
$this->Flash->error(__('The user could not be saved. Please, try again.')); | |
} | |
} | |
$this->set(compact('user')); | |
$this->set('_serialize', ['user']); | |
} | |
?> | |
It will create notice on submit on if($this->Users->Save($user)) | |
Notice (8): Array to string conversion [CORE\src\Database\Statement\MysqlStatement.php, line 39] | |
Notice (8): Array to string conversion [CORE\src\Database\Log\QueryLogger.php, line 92] | |
As of the moment the codes above can upload the actual image in the users directory but destination field in users table is empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment