Welcome Guest, Not a member yet? Register   Sign In
CI3.1.7 Upload Image Sometime Failed
#1

Hello,

I found some strange thing.
I have two images, but I can only upload one of them.
https://ibb.co/j1U0yb

I can upload 456.jpg,
but I can't upload 123.jpg (it will upload noimage.jpg instead)

This is my controller's code
PHP Code:
$config['upload_path'] = './assets/images/event/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$config['max_width'] = '1500';
$config['max_height'] = '1500';
$config['remove_spaces'] = FALSE;

$this->load->library('upload'$config);
if(!
$this->upload->do_upload('userfile')){
 
 $errors = array('error'=> $this->upload->display_errors());
 
 $post_image 'noimage.jpg';
}else{
 
 $data = array('upload_data' => $this->upload->data());
 
 $post_image $_FILES['userfile']['name'];
}
$this->Event->create_events($post_image);
$this->session->set_flashdata('event_created','Your event has been created');
redirect('events'); 
Anyone have idea?

Thank you very much in advance.

Attached Files Thumbnail(s)
   
Reply
#2

(01-22-2018, 03:55 PM)forfunonly Wrote: Hello,

I found some strange thing.
I have two images, but I can only upload one of them.
https://ibb.co/j1U0yb

I can upload 456.jpg,
but I can't upload 123.jpg (it will upload noimage.jpg instead)

This is my controller's code
PHP Code:
$config['upload_path'] = './assets/images/event/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$config['max_width'] = '1500';
$config['max_height'] = '1500';
$config['remove_spaces'] = FALSE;

$this->load->library('upload'$config);
if(!
$this->upload->do_upload('userfile')){
 
 $errors = array('error'=> $this->upload->display_errors());
 
 $post_image 'noimage.jpg';
}else{
 
 $data = array('upload_data' => $this->upload->data());
 
 $post_image $_FILES['userfile']['name'];
}
$this->Event->create_events($post_image);
$this->session->set_flashdata('event_created','Your event has been created');
redirect('events'); 
Anyone have idea?

Thank you very much in advance.

Maybe this might help.
I came across a situation where a file had the wrong extension - png instead of jpg. This was not obvious because the linux/window viewer showed the image as it should appear but didn't report it as being the wrong extension.
the function getimagesize(...) gave the mime-type of this image as image/jpeg
the public function "is_allowed_filetype($ignore_mime = FALSE)" at circa line 890 in system/libraries/upload checks the mime type for png ie image/png,image/x-png against the file_type which is set by getimagesize() and is therefore image/jpeg
image/jpeg is not in the array of allowed image types image/png,image/x-png so it reported the file type as "not allowed"
which gave the misleading impression that png files are not allowed. The result was upload->doupload returned false when trying to upload an image which, on the face of it, was valid.
Bill
Reply




Theme © iAndrew 2016 - Forum software by © MyBB