Php 我想将图像路径存储在数组中,索引为用户在codeigniter中发送电子邮件
我正在尝试上载根目录中上载文件夹中用户的图像,但我不想创建一个全局数组,因为每个人都不能上载其图像,只有某些人可以上载,因此我愿意创建一个全局数组,在用户成功添加前调用该数组,该数组将扩展为用户电子邮件时的索引数组还有图像$config的完整路径[full_path]或者其他一些我不清楚的东西,若你们能解释一下,那个就太好了,所以我在codeigniter中创建了一个全局数组,但它不起作用 我的控制器Php 我想将图像路径存储在数组中,索引为用户在codeigniter中发送电子邮件,php,ajax,codeigniter,Php,Ajax,Codeigniter,我正在尝试上载根目录中上载文件夹中用户的图像,但我不想创建一个全局数组,因为每个人都不能上载其图像,只有某些人可以上载,因此我愿意创建一个全局数组,在用户成功添加前调用该数组,该数组将扩展为用户电子邮件时的索引数组还有图像$config的完整路径[full_path]或者其他一些我不清楚的东西,若你们能解释一下,那个就太好了,所以我在codeigniter中创建了一个全局数组,但它不起作用 我的控制器 class Welcome extends CI_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);
}}
我不确定,我没有弄错你的问题。为了给全局变量赋值,应该使用
$this
$this->slogan[$this->input->post('email')] = $candidateSlogan['full_path'];
我使用了$LANGOSON[$this->input->post('email')]=$candidateSlogan['full_path'],我想创建一个全局数组,在其中存储图像路径,然后在视图中调用该数组来显示该图像。不仅仅是
$LANGOSON
。您应该使用$this->slogan
如果我像未定义变量slogan一样使用$this->slogan,则返回错误请查看guid。