Welcome Guest, Not a member yet? Register   Sign In
Excel Upload via File Upload Library
#1

[eluser]Josh Kendall[/eluser]
I'm trying to upload a Excel file (.xls format) to my server through a form on my CI based web site. I keep getting a "The filetype you are attempting to upload is not allowed" error. I'm not sure why I'm getting this as I have xls as the only allowed_types and I even modified mimes.php to reflect the octet-stream issue that I found when I was searching for this issue.

Controller Function:
Code:
function upload(){

    $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/uploads/excel/';
    $config['allowed_types'] = 'xls';
    $config['max_size']    = '10000';
    $this->load->library('upload', $config);
    if(!$this->upload->do_upload()){
        echo $this->upload->display_errors();
        preprint($this->upload->data());
        preprint($_FILES);
    } else {
        redirect('../../../excel/import/users::'.$_FILES['userfile']['name']);
        exit();
    }
}

And here is the line in Mimes.php
Code:
'xls'    =>    array('application/vnd.ms-excel', 'application/octet-stream', 'application/msexcel', 'application/excel'),

and still it doesn't work. Does anyone have any suggestions?
#2

[eluser]Seppo[/eluser]
Try echoing $_FILES['userfile']['type'] to check the mime type and add it to the allowed mime type array.
After that, you can post the mime here so the CI devs can add it for the next versions =)
#3

[eluser]Josh Kendall[/eluser]
It says it's
Code:
\"application/excel\"
. I added that and now it tells me "Invalid file format".
#4

[eluser]Seppo[/eluser]
Oh Sad
Try debugging the is_allowed_filetype method inside the upload library.. The line 543 is the one that should allow/deny it.
#5

[eluser]Josh Kendall[/eluser]
Actually, I just edited my last reply. I had only added
Code:
application/excel
but it was looking for
Code:
\"application/excel\"
#6

[eluser]Josh Kendall[/eluser]
Never mind about the "Invalid File Format" issue. That's not with the upload. That's with the next step of the process, and something I can take care of.

Here is my XLS mime information from mimes.php

Code:
'xls'    =>    array('application/vnd.ms-excel', 'application/octet-stream', 'application/excel', '\"application/excel\"', '"application/excel"'),

Thanks for the help Seppo.
#7

[eluser]Unknown[/eluser]
You can add

Code:
application/x-msexcel

to the list of MIME types as well. I got that one on my Windows XP machine just now.
#8

[eluser]jabbett[/eluser]
Firefox running in Ubuntu reports an Excel upload as 'application/xls'

Is there anyway to just shut off the mime-type requirement, and allow upload of any file type? I'm really getting burned by all the different ways browsers/OSes describe Excel.
#9

[eluser]Seppo[/eluser]
You could extend the upload class, and override the file type validation method...
#10

[eluser]joneslee[/eluser]
Is there any reason why CI doesn't pick up Excel file mimetype correctly? My uploaded excel is regconized as 'application/octet-stream' which make me go through another step to check file_ext to make sure that is an Excel file.




Theme © iAndrew 2016 - Forum software by © MyBB