我想通过codeigniter在数据库中上传图像,图像不在数据库中上传

时间:2017-04-10 16:31:30

标签: php codeigniter

这是我的控制器块;我无法理解如何在模型中发帖。当我使用这些行'image_path'=>$image_path时,它显示错误。

 <?php
 defined('BASEPATH') OR exit('No direct script access allowed');

 class User_index extends CI_Controller {
 public function index()
{
    $this->load->view('user/user_index_view');
}

public function signup_validation(){
$this->form_validation->set_rules('name','Name','required|trim');
$this->form_validation->set_rules('email','Email','required|trim');
$config = [
    'upload_path' =>    './uploads',
    'allowed_types'=>   'jpg|gif|png|jpge',
    'max_size'=>    '1024',

    ];
    $this->load->library('upload', $config);
if ($this->form_validation->run() && $this->upload->do_upload()){
        $data = $this->upload->data();

        //echo "<pre>";
        //print_r($data); exit;
        $image_path = base_url("uploads/".$data['raw_name'].$data['file_ext']);

        $post['image_path'] = $image_path;

        //echo $image_path; exit;
    $key = md5(uniqid());
    $this->load->model('mainsignupmodel');
        $this->email->set_mailtype('html');
        $this->email->from(--------------------);   
        $this->email->to($email = $this->input->post('email'));
        $this->email->subject("Confirm Your Account.");
        $message ="<p>Thank You for Signing Up!<P>";
        $message .= "<p><a href='".base_url()."user_welcome/register_user/$key'>Click Here</a>to confirm your account</P>";
        $this->email->message($message);
        if ($this->mainsignupmodel->add_temp_user($key)){
            if($this->email->send()){
            $this->session->set_flashdata('feedback_class',"A welcome message with further instructions has been sent to your e-mail address.");
            $this->session->set_flashdata('feedback','alert-success');
            redirect('user_index/signup_validation');
        }else {
            $this->session->set_flashdata('feedback_class',"Email has not been sent, Try again.");
        $this->session->set_flashdata('feedback','alert-danger');
        return redirect('user_index/signup_validation');
        }
        }else echo "Problem adding to database.";   


} else {
    $upload_error = $this->upload->display_errors();
    $this->load->view('user/user_index_view',compact('upload_error'));

}

}
}

这是我的模型块。

<?php class Mainsignupmodel extends CI_Model
 {
public function add_temp_user($key){
    $data = array(
    'name' => $name = $this->input->post('name'),
    'email' => $email = $this->input->post('email'),
    'date_time' => $date = $this->input->post('date_time'),
    'status' => $status  = $this->input->post('status'),


    'mail_key' => $key

    );


    $q = $this->db->insert('temp_user',$data);

    if ($q) {
        return true;

    }else{
        return FALSE;
    }
}

}

0 个答案:

没有答案