[英]I want to store image path in array with index as users email in codeigniter
I'm trying to upload an image of a user in upload folder present at root directory not I want to create a global array because every person can't upload it's image only certain person can so I'm willing to create a global array which will be called before User Added Successfully which extends an array with index as users email and full path of the image $config[full_path] or something else I'm not cleared about that it would be great if you are able to explain that also so i created a global array in codeigniter but that's not working.我正在尝试在根目录下的上传文件夹中上传用户的图像,而不是我想创建一个全局数组,因为每个人都不能上传它的图像,只有某些人可以,所以我愿意创建一个全局数组将在用户添加成功之前被调用,它扩展了一个数组,索引为用户电子邮件和图像的完整路径 $config[full_path] 或其他我不清楚的东西,如果你能解释一下,那也很好我在 codeigniter 中创建了一个全局数组,但这不起作用。
My Controller我的控制器
class Welcome extends CI_Controller {
$slogan = array();
public function add_user_validation(){
$this->form_validation->set_rules("firstName", "First Name", "required|trim|alpha");
$this->form_validation->set_rules("lastName", "Last Name", "required|trim|alpha");
$this->form_validation->set_rules("email", "Email", "required|trim|valid_email");
$this->form_validation->set_rules("password", "Password", "required");
$this->form_validation->set_rules("passwordMatch", "Password Comfirmation", "required|matches[password]");
$this->form_validation->set_rules("userStatus", "User Status", "required");
// if(!empty($_FILES['candidateSlogan'])){
if(isset($_FILES['candidateSlogan'])){
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'png|jpg|jpeg';
}
if ($this->form_validation->run()) {
$this->load->model('main_model');
$data = array(
"first_name" => $this->input->post('firstName'),
"last_name" => $this->input->post('lastName'),
"email" => $this->input->post('email'),
"password" => $this->input->post('password'),
"user_status" => $this->input->post('userStatus')
);
if($this->main_model->search_user_if_new($data)){
if($this->input->post('userStatus') == 'candidate'){
$this->load->library('upload', $config);
if($this->upload->do_upload('candidateSlogan')){
$candidateSlogan = $this->upload->data();
// print_r($candidateSlogan);
if($this->main_model->add_user($data)){
$slogan[$this->input->post('email')] = $candidateSlogan['full_path'];
$success['message'] = 'User Added Successfully';
echo json_encode($success);
}
else{
$error['message'] = 'An error Occured';
}
}
else{
$error = array(
'file_error' => $this->upload->display_errors(),
'message' => 'Error'
);
echo json_encode($error);
}
}
else if($this->main_model->add_user($data)){
$success['message'] = 'User Added Successfully';
echo json_encode($success);
}
}
else{
$error['message'] = 'User Already Exists';
echo json_encode($error);
}
}
else{
$data = array(
'message' => 'Error',
'firstName' => form_error('firstName'),
'lastName' => form_error('lastName'),
'email' => form_error('email'),
'password' => form_error('password'),
'passwordMatch' => form_error('passwordMatch'),
'userStatus' => form_error('userStatus')
);
echo json_encode($data);
}}
I'm not sure, I get your question correctly.我不确定,我正确地理解了你的问题。 In order to assign a value to a global variable, you should use
$this
.为了给全局变量赋值,你应该使用
$this
。
$this->slogan[$this->input->post('email')] = $candidateSlogan['full_path'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.