Welcome Guest, Not a member yet? Register   Sign In
Image Upload Problem (The filetype you are attempting to upload is not allowed.)
#1

[eluser]DannGrant[/eluser]
Hi guys,

Sorry to bother you all, i know this problem exists and i've looked through the threads and i'm still struggling to come up with a solution.

The error i'm getting is 'The filetype you are attempting to upload is not allowed.'

This is my code, and it's getting caught at the do_upload().

Here's my code :[

Code:
function create()
{
  if($this->input->post('submit'))
  {
   $this->load->library('form_validation');
  
   $this->form_validation->set_rules('first_name', 'First Name', 'required|trim');
   $this->form_validation->set_rules('last_name', 'Last Name', 'required|trim');
   $this->form_validation->set_rules('position', 'Position', 'required|trim');
   $this->form_validation->set_rules('club_role', 'Club Role', 'required|trim');
   $this->form_validation->set_rules('funny_moment', 'Funniest Cricketing Moment', 'required|trim');
   $this->form_validation->set_rules('best_moment', 'Best Cricketing Moment', 'required|trim');
  
   if($this->form_validation->run() == FALSE)
   {    
    $data['main_content'] = 'players/create';
    
    $this->load->view('inc/template', $data);
   }
   else
   {
    $config['upload_path'] = './uploads/players/';
    $config['allowed_types'] = 'jpg|png';
    $config['max_size'] = '2000';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';
    $config['remove_spaces'] = TRUE;
    
    $this->load->library('upload', $config);
    
    if(!$this->upload->do_upload())
    {
     $data['error'] = array('error' => $this->upload->display_errors());
      
     $data['main_content'] = 'players/main';
     $this->load->view('inc/template', $data);
    }
    else
    {
     $data = array('upload_data' => $this->upload->data());
    
     $this->load->model('player_model');
    
     $player = array(
      'player_id'  => $this->input->post('player_id'),
      'first_name' => $this->input->post('first_name'),
      'last_name'  => $this->input->post('last_name'),
      'position'  => $this->input->post('position'),
      'club_role'  => $this->input->post('club_role'),
      'funny_moment' => $this->input->post('funny_moment'),
      'best_moment' => $this->input->post('best_moment'),
      'image_url'  => 'uploads/players/' . $this->upload->data('orig_name')
     );
    
     $query = $this->player_model->add($player);
    
     redirect('players');
    }
   }
  }
  else
  {
   $data['main_content'] = 'players/create';
  
   $this->load->view('inc/template', $data);
  }
}
#2

[eluser]raenk[/eluser]
Do this for the line reporting the error:
Code:
$data['error'] = $this->upload->display_errors() . $_FILES['userfile']['type'];

That way you will learn what file type is sending your browser and if it is actually allowed. Also don't forget to check mimes.php at your application/config and look at the array for the appropiate file extension and mime type.

By the way, I simplified what you had before on that line as you can see.
#3

[eluser]DannGrant[/eluser]
Thanks for your speedy reply! That line works a treat.

However, what am i looking for in mimes.php?

Code:
'gif' => 'image/gif',
    'jpeg' => array('image/jpeg', 'image/pjpeg'),
    'jpg' => array('image/jpeg', 'image/pjpeg'),
    'jpe' => array('image/jpeg', 'image/pjpeg'),
    'png' => array('image/png',  'image/x-png'),

That's what i have at the minute, with regards to the jpg i'm uploading.

Thanks again.
#4

[eluser]raenk[/eluser]
Just check if the mime type reported at the error matches an element you have in the mimes array. If not, add it, if does then welcome to the unresolved mysteries of the CI file uploading class.
#5

[eluser]DannGrant[/eluser]
Aha, looks like it's going that way.

How fantastic...
#6

[eluser]raenk[/eluser]
Yeah, I'm stuck also as you can see: http://ellislab.com/forums/viewthread/209157/
#7

[eluser]TheFuzzy0ne[/eluser]
I've given some advice [url="http://ellislab.com/forums/viewthread/209157/#973733"]here[/url], which is where I hope to continue providing support for this issue. It makes sense to use the same thread since you're both experiencing the same issue.




Theme © iAndrew 2016 - Forum software by © MyBB