我希望在codeigniter中上传固定大小的图片。但是我的代码无效。任何人请帮我做这个..我的代码是
public function createevent() {
if ($this->input->post('submit')) {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_width'] = '366';
$config['max_height'] = '269';
$this->load->library('upload', $config);
// $data = array('upload_data' => $this->upload->data());
$data = $this->upload->data();
$logo = $data['file_name'];
$fileInfo = getimagesize($data);
if( $fileInfo['width'] == 366 && $fileInfo['height'] == 269 ) {
// if(($fileInfo[0] == 366) && ($fileInfo[1] == 269 )){
// if ($this->upload->do_upload()) {
$this->event_model->createevent( $logo);
$this->session->set_flashdata('msg', 'Event Created');
} else {
// $this->image_lib->resize();
$this->session->set_flashdata('error', 'Please upload image within the size limit');
redirect('event/events');
}
}
}
答案 0 :(得分:0)
请使用$fileInfo['image_width']
& $fileInfo['image_height']
代替
$fileInfo['width']
& $fileInfo['height']
这会奏效。 :)