Upload Photo Failed Codeigniter

前端 未结 1 1142
闹比i
闹比i 2021-01-16 01:28

This is my code, my photo can\'t be inserted into the database.

Actually I want to make an online exam with the codeigniter. I want to upload the question with the p

相关标签:
1条回答
  • 2021-01-16 01:36

    Kindly use this code

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Dashboard extends CI_Controller{
        function __construct(){
            parent::__construct();
            $this->load->model('soal_model');
    }
    
    function insert()
    {
        $config =array(
            'upload_path' => './images',
            'allowed_types' => 'gif|jpg|png|jpeg',
            'max_size' => '2500',
        );
        $this->load->library('upload', $config);
    
        $this->upload->do_upload('file_upload');
    
        $upload_data = $this->upload->data();   
    
        $file_name = $upload_data['file_name'];
        $data = array(
            'foto' => $file_name,
        );
    
        $hasil = $this->soal_model->Simpan('soal', $data);
    
        if($hasil>=1){
            redirect('dashboard/index', $data);
        }
    }   
    ?>
    
    0 讨论(0)
提交回复
热议问题