我想使用CodeIgniter將圖像上傳到數據庫我使用以下代碼。現在它顯示錯誤「您沒有選擇要上傳的文件」。即使我選擇了。任何人都可以說我的代碼有什麼錯誤。我無法使用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('[email protected]');
$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";
}
}
}
?>
將圖像路徑放置應用程序文件夾? –
[圖片上傳不能在codeignitor中工作]的可能的重複(http://stackoverflow.com/questions/29698048/image-upload-not-working-in-codeignitor) –
你面臨什麼問題? –