douteng5673 2015-12-22 11:57
浏览 41

CodeIgniter上传功能,有时不起作用

I have problem with codeigniter upload function. The function works well, but sometimes didn't work and without any error info.

snippet in controller

...
        function add_process() {
                $data['title'] = anchor('event/','<b>EVENT</b>', array('class' => 'back'));
                $data['subtitle'] = ' / Add Event';
                $data['main_view'] = 'event/event_form';
                $data['form_action'] = site_url('event/add_process');       

                $this->form_validation->set_rules('eventName', 'Event Name', 'required');
                $this->form_validation->set_rules('eventDate', 'Event Date', 'required');
                if (empty($_FILES['eventImage']['name'])){
                    $this->form_validation->set_rules('eventImage', 'Event Image', 'required');     
                }               

                if ($this->form_validation->run() == TRUE) {    
                    $config['upload_path'] = './images/event/';
                    $config['allowed_types'] = 'jpg|jpeg|png';          
                    //$config['max_width'] = '3000';
                    //$config['max_height'] = '3000';

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

                    $this->upload->do_upload('eventImage');
                    $eventImage = $this->upload->data();

                    $event = array( 'eventName'         => $this->input->post('eventName'),
                                    'eventDate'         => date('Y-m-d', strtotime($this->input->post('eventDate'))),
                                    'eventDescriptions' => $this->input->post('eventDescriptions'),
                                    'eventImage'        => 'images/event/'.$eventImage['file_name'],
                                    'isActive'          => $this->input->post('isActive')
                                );
                    $this->Event_model->add($event);            

                    $this->session->set_flashdata('message', '1 record was successfully added!');
                    redirect('event/add');      

                } else  {           
                    $this->load->view('admin/admin_main', $data);
                }
            } 
    ...

could you tell please, what am i missing here?

  • 写回答

1条回答 默认 最新

  • doubomudichen0832 2015-12-22 12:58
    关注

    Replace this

    $this->Event_model->add($event);            
    
    $this->session->set_flashdata('message', '1 record was successfully added!');
    redirect('event/add'); 
    

    to this

    if ($this->Event_model->add($event)) {
        $this->session->set_flashdata('message', '1 record was successfully added!');
        redirect('event/add'); 
    }  
    
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效