0

I want to ask about codeigniter upload.

Codeigniter version 2.1.4

I cant upload the image into the folder online, but it works perfectly on localhost.

My code for upload image

$config['upload_path'] = './assets/frontend/images/banner/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['max_width']  = '0';
$config['max_height']  = '0';
$this->upload->initialize($config);
$this->upload->do_upload('BannerImg');
$banimg = $this->upload->data();

$bantitle = $this->input->post('BannerTitle');
$bandesc = $this->input->post('BannerDesc');
$this->banner_model->addBanner($banimg,$bantitle,$bandesc);

Do you know what's the problem?

Already try searching for it but can't find the solution.

Please if someone can help me.

Thanks.

Kypros
  • 2,997
  • 5
  • 21
  • 27
quantum_rez
  • 13
  • 1
  • 8
  • Are you getting any errors ? Have you checked your server logs? – Kypros Oct 26 '14 at 11:26
  • Hi,@Kypros thanks for your quick reply. I dont get any errors. That's why I dont understand what's wrong with my code. On Localhost it works perfectly but after I upload it to server online, my image not inserted to the upload path. Do you know what's wrong? Thank You – quantum_rez Oct 26 '14 at 11:36
  • Tough to "guess" without any actual error logs if it works locally. Checking if that directory exists, it's permissions and access group would be a first step to finding what's not working. – Kypros Oct 26 '14 at 11:38
  • @kypros do you know how I can get the error logs in my code? the directory is exist, permission already 777 in my server. – quantum_rez Oct 26 '14 at 11:45
  • Edit your answer to include the Operating System you are using, the Server (`apache`/`nginx` etc) and any other information you think could be useful. Are you using a private server or a shared host? – Kypros Oct 26 '14 at 11:47
  • cant edit my answer @Kypros this is all from my cpanel hope this will help the directory is exist, permission already 777 in my server. This is from my cpanel cPanel Version 11.44.1 (build 19) Apache version 2.2.26 PHP version 5.2.17 MySQL version 5.5.37-cll Architecture x86_64 Operating system linux phpmyadmin Database Server Server: Localhost via UNIX socket Server type: MySQL Server version: 5.5.37-cll - MySQL Community Server (GPL) Protocol version: 10 Server charset: UTF-8 Unicode (utf8) – quantum_rez Oct 26 '14 at 11:58
  • @Kypros just wondering, is it because in linux I dont have temp folder just like localhost on my windows? Because when I echo temp folder. on my localhost the result C:\xampp\tmp but in my server the result is blank. do you think this is the problem? But now I dont know how can I create temp folder in my linux server. Hope you will help me again. Thank You – quantum_rez Oct 26 '14 at 12:25
  • Try adding `if ( ! $this->upload->do_upload('BannerImg')) { $error = array('error' => $this->upload->display_errors()); print_r($error); }` where you have the `do_upload` line to see if the upload class produces any errors – Kypros Oct 26 '14 at 13:01
  • @Kypros wow, I got the error. Array ( [error] => The filetype you are attempting to upload is not allowed. The filetype you are attempting to upload is not allowed. ) What does it mean? I already set the allowed type in my controller above. Something wrong with it? – quantum_rez Oct 26 '14 at 13:11
  • If you set `$this->upload->set_allowed_types('*');` it works right? – Kypros Oct 26 '14 at 13:14
  • @Kypros yeah, it works perfectly. I dont use $config['allowed_types'] = 'gif|jpg|png'; but use $this->upload->set_allowed_types('*'); after $this->upload->do_upload('BannerImg'); This will work for any file type right?But why this happen? – quantum_rez Oct 26 '14 at 13:20
  • @kypros sorry, but It seems doesnt work if the file size is too large, do you know how can I change the max uploaded file size? I dont know where to change it in server. In localhost I know to change it in php.ini. Thank you – quantum_rez Oct 26 '14 at 13:38
  • Since i believe you are on shared host you will have to contact their support department and ask for that change and if they allow you to. – Kypros Oct 26 '14 at 13:41
  • 1
    @kypros oh okay got it. I think there's another way to achieve it, but I'll ask them about it. thank you for your help, it's really helpful :D – quantum_rez Oct 26 '14 at 13:43

1 Answers1

0

Since we found the problem in the comments, i'll just post it here as a reference. Basically the issue is with the upload_class in codeigniter which seems to be bugged involving some mime types. See similar problems:

  1. CodeIgniter: "The filetype you are attempting to upload is not allowed."

  2. CodeIgniter "The filetype you are attempting to upload is not allowed." (not the same as 1.)


Quoting the accepted answer from point 1 above:

You are using Firefox, aren't you?

You could try looking at system/libraries/Upload.php line 199:

$this->_file_mime_type($_FILES[$field]);

Change that line to:

$this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();

Then do upload your .wmv file. It would show something like application/octet-stream or whatever. Add that to your mimes.php. Hope this help =)

Similar answer here

Note: In your case it won't probably wont be exactly the same but the issue is similar and you should find the relevant file types as in the answer and add them to the mimes.php file to solve this issue.

Some links:

Community
  • 1
  • 1
Kypros
  • 2,997
  • 5
  • 21
  • 27
  • For me it shows the correct mime types. It works fine on localhost but not online. Any thoughts? Thanks! – itsols Jun 07 '17 at 06:38