【发布时间】:2016-03-28 16:39:32
【问题描述】:
我在使用 codeigniter 上传功能时遇到问题。 该功能运行良好,但有时不起作用并且没有任何错误信息。
控制器中的sn-p
...
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);
}
}
...
你能告诉我,我在这里缺少什么吗?
【问题讨论】:
-
将
$this->upload->do_upload('eventImage');替换为if ( ! $this->upload->do_upload('eventImage')) { $error = array('error' => $this->upload->display_errors()); var_dump($error); }看看你有什么错误。 -
啊,我明白了,这是为了捕捉错误,对吧?如果函数显示错误,我会通知您。谢谢@Mirceac21
-
其实已经找到问题了,有人把$config['max_width'] = '3000'的评论标签去掉了。因此,当尝试上传巨大的图像时,就会出现问题。 PS:而那个人就是我,多么...
标签: php codeigniter image-uploading