0

I'm trying to upload a file on CodeIgniter 2 but it fails. I tried a few different ways, actually CI is getting the file and trying to put it in destination folder but I think there is a problem with folder permissions. Because I can echo file name etc.

This is my model file's related part:

$config =   array
    (
    'upload_path'       =>  'uploads/campaigns/data',
    'allowed_types'     =>  'csv',
    );
    $this->upload->initialize($config);
    $this->upload->do_upload('file');

    $file       =   $this->upload->data();
    $file_name  =   $file['file_name'];

    if(!empty($file_name)) {

        echo $file_name;
    }
    else {
        echo $this->upload->display_errors();
    }

With this code, I can see filename but file is not uploading. I only have root account on this server and all files created and owned by root. Folders have 777 permission. What should I try now?

Thank you!

Deniz B.
  • 2,532
  • 1
  • 18
  • 35

2 Answers2

1

Use this to track your errors

if ( ! $this->upload->do_upload())
{
    echo $this->upload->display_errors();
}
else
{
    echo "success";
}

I hope you loaded the library as well

EDIT 01

$config['upload_path'] = './uploads/campaigns/data';
$config['allowed_types'] = 'csv';
$config['max_size'] = '5120'; # 5MB allowd

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
    echo $this->upload->display_errors();
}
else
{
    echo $this->upload->data();
}

And in application/config/mimes.php

Check there is a csv format. If ot exist add this on array as new item

'csv'   =>  array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

I think there is an issue with Upload library of the Codeigniter. See link for more details and I hope this will help you.

Community
  • 1
  • 1
Vikash Kumar
  • 1,091
  • 9
  • 16