下面的代码是更新数据库,但它没有上传图像,我检查了文件夹权限。先感谢您。我有更新来显示整个功能。整个功能正在运行,只有上传不起作用。
public function update_company()
{
$distributor = $this->aauth->get_user();
$distributor_id = $distributor->distributor_id;
$company_name = $this->input->post("company_name");
$contact_name = $this->input->post("contact_name");
$number = $this->input->post("number");
$email = $this->input->post("email");
$address = $this->input->post("address");
if(empty($company_name))
{
$message = '<p style="color: red;">Please enter the company name!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else if(empty($contact_name))
{
$message = '<p style="color: red;">Please enter the contact name!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else if(empty($number))
{
$message = '<p style="color: red;">Please enter the phone number!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else if(empty($email))
{
$message = '<p style="color: red;">Please enter the email address!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else if(empty($address))
{
$message = '<p style="color: red;">Please enter the address!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else if (strlen($company_name) < 2)
{
$message = '<p style="color: red;">The length of the company name is too short!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else if (strlen($contact_name) < 2)
{
$message = '<p style="color: red;">The length of the contact name is too short!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else if (strlen($number) < 9)
{
$message = '<p style="color: red;">The length of the phone number is too short!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else if (strlen($address) < 2)
{
$message = '<p style="color: red;">The length of the address is too short!</p> <br />';
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
return;
}
else
{
$this->load->library('upload');
if ($_FILES['userfile']['size'] > 0)
{
$this->upload->initialize(array(
"upload_path" => base_url().'/assets/uploads/distributors/',
"overwrite" => FALSE,
"max_filename" => 250,
"encrypt_name" => TRUE,
"remove_spaces" => TRUE,
"allowed_types" => "gif|jpg|png|jpeg|",
"max_size" => 500,
"xss_clean" => TRUE,
"max_width" => 600,
"max_height" => 150
));
if (!$this->upload->do_upload('picture')) {
$message = 'Failed to upload the image';
}
$data = $this->upload->data();
$picture = $data['file_name'];
}
else
{
$picture = 'default.jpg';
}
$message = '<p style="color: green;">You succesfully updated your company profile</p> <br />';
$this->customer_model->update_distributor($distributor_id, array(
"company_name" => $company_name,
"contact_name" => $contact_name,
"number" => $number,
"email" => $email,
"address" => $address,
"picture" => $picture
)
);
$this->session->set_flashdata('message', $message);
redirect('/your_profile/company');
}
}
答案 0 :(得分:0)
由于路径错误,图片无法上传...
所以
"upload_path" => './assets/uploads/users'
更改为
"upload_path" => './assets/uploads/users/'
管理上传路径的最佳方法是通过加载base_url()
帮助程序来使用url
。
答案 1 :(得分:0)
首先你的路径无效。尝试纠正@Hikmat Sijapati建议的路径。 接下来,您不会检查实际出现的错误。如果您的文件上传失败,请尝试使用$ this-&gt; upload-&gt; display_errors()检查错误。