【发布时间】:2015-07-13 10:16:16
【问题描述】:
我想使用 CodeIgniter 将图像上传到数据库我使用以下代码。现在它显示错误“您没有选择要上传的文件”。即使我选择了。谁能说出我的代码有什么错误。
<?php
class Register_form_controller extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library('form_validation','validation');
}
function index()
{
$this->form_validation->set_rules('name','name','required');
$this->form_validation->set_rules('age','age','required');
$this->form_validation->set_rules('gender','gender','required');
$this->form_validation->set_rules('mobilno','mobilno','required');
$this->form_validation->set_rules('email','email','required|valid_email|is_unique[register.email]');
$this->form_validation->set_rules('uname','username','required');
$this->form_validation->set_rules('password','password','required|matches[cpassword]');
$this->form_validation->set_message('cpassword','password mismatched','required');
$this->form_validation->set_rules('cpassword','cpassword','required');
if($this->form_validation->run() == FALSE)
{
$this->load->view("Register_form_view");
}
else
{
$this->doregister();
}
}
function doregister()
{
if($this->input->post("submit"))
{
$config = array( "upload_path" => "image/",
"allowed_types" => "jpg|gif|jpeg|png",
"max_size" => "2048",
"max_width" => "",
"max_height" => ""
);
$this->load->library("upload",$config);
if($this->upload->do_upload('image'))
{
$upload_data = $this->upload->data(); //echo"<pre>"; print_r($upload_data); exit;
}
else
{
echo $error = $this->upload->display_errors(); //echo"<pre>"; print_r($error); exit;
}
$name = $this->input->post('name');
$age = $this->input->post('age');
$gender = $this->input->post('gender');
$mobno = $this->input->post('mobilno');
$email = $this->input->post('email');
$uname = $this->input->post('uname');
$pass = $this->input->post('password');
$cpass = $this->input->post('cpassword');
$image = $upload_data['file_name'];
$data = array( 'name' => $name,
'age' => $age,
'gender' => $gender,
'mobilno' => $mobno,
'email' => $email,
'uname' => $uname,
'password' => $pass,
'image' => $image
);
//echo"<pre>"; print_r($data); exit;
//$this->load->library('form_validation');
$this->load->model("Register_model","register");
if($this->register->insertData($data))
{
$this->load->library("email");
$this->email->from('magesh0312@gmail.com');
$this->email->to($email);
$this->email->subject('Confirmation message');
$message = "you Registred successfully \n";
$message = "Thank you for joining";
$this->email->message($message);
if($this->email->send())
{
echo 'success';
echo"Registred successfully";
}
else
{
echo "mail has send failed";
echo" but you joined the group";
}
//redirect('Register_form_controller/index');
}
}
else
{
echo"registration failed";
}
}
}
?>
【问题讨论】:
-
图像路径放在应用程序文件夹之外??
-
你遇到了什么问题?
-
我无法上传图片它显示错误消息“您没有选择要上传的文件。”即使我选择了图片
-
@wolfgang1983 但这不是问题,我改了好几次。
标签: php image codeigniter file-upload