codeigniter image upload cant grab file name

℡╲_俬逩灬. 提交于 2019-12-06 15:38:55

I have edited your code. It may be work for you. If your folder is in root folder of application then no need to use APPPATH. I have also edited this in your code. Try this.

//Write post when logged in as admin
function write()
{
    //insert image
    $config['upload_path'] = 'archive/img/news/';
    $config['allowed_types'] = 'gif|jpg|jpeg|png';
    $config['max_size']         = '9000';
    $config['encrypt_name']     = true;

    $this->load->library('upload', $config);
    $this->upload->do_upload('newsImage');

    $file_data = $this->upload->data();

    $newsData = array(
        'headline'      => $this->input->post('headline'),
        'description'   => $this->input->post('description'),
        'content'       => $this->input->post('content'),
        'creater'       => $this->session->userdata('username'),
        'ip'            => $this->session->userdata('ip'),
        'imgPath'       => $_FILES['newsImage']['name']
    );


    echo "<pre>";
    //print_r( $this->upload->data());
    //print_r($file_data);
    //print_r($_FILES);
    //print_r($this->input->post());
    print_r($newsData);
    echo "</pre>";


    $this->load->model('admin/news_model');
    $this->news_model->insertNews($newsData);


    $data['main_content'] = 'admin/write_view';
    $this->load->view('template', $data);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!