我正在尝试使用CodeIgniter的上传库,但我一直在收到错误:
A PHP Error was encountered
Severity: Warning
Message: strrpos() expects parameter 1 to be string, array given
Filename: libraries/Upload.php
Line Number: 1178
Backtrace:
File: C:\xampp\htdocs\schoolPortal\application\controllers\StudentAffairs.php
Line: 207
Function: do_upload
File: C:\xampp\htdocs\schoolPortal\index.php
Line: 292
Function: require_once
我不知道错误是什么,因为我只是在相同控制器的其他功能中复制了相同的代码,但是那个正在运行。
以下是控制器中代码的示例:
$img_name = $this->InfoModel->getFirstNullAnnouncement();
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 5000;
$config['max_width'] = 3000;
$config['max_height'] = 4000;
$config['overwrite'] = TRUE;
$config['file_name'] = $img_name;
$this->load->library('upload', $config);
$this->upload->initialize($config);
$img = "userfile";
$id = $this->session->userdata('id');
$user['user'] = $this->UsersModel->select_student_affairs($id);
if (!$this->upload->do_upload($img)){
$data['error'] = $this->upload->display_errors();
$this->load->view('include/header_student_affairs',$user);
$this->load->view('studentaffairs/add_announcement', $data);
$this->load->view('include/footer_student_affairs');
} else {
$img_path = 'images/'.$this->upload->data('orig_name');
$data['success'] = 'Announcement has been updated.';
$data['announcements'] = $this->InfoModel->getAnnouncements();
$data['announcenum'] = $this->InfoModel->getAnnouncementCount();
$this->InfoModel->updateAnnouncement($img_path);
$imgdata = $this->upload->data();
$thumbnail = $imgdata['raw_name'].'_thumb'.$imgdata['file_ext'];
$this->createThumbnail($img_path, $img_id, $thumbnail);
$this->load->view('include/header_student_affairs',$user);
$this->load->view('studentaffairs/announcements', $data);
$this->load->view('include/footer_student_affairs');
}
第207行就是这个:
if (!$this->upload->do_upload($img)){
$this->upload->display_errors();
会产生错误:T he filetype you are attempting to upload is not allowed.
请帮忙
答案 0 :(得分:0)
也许您要上传的文件的扩展名为.jpeg
,而$config['allowed_types']
列表中没有该文件。