Welcome Guest, Not a member yet? Register   Sign In
BUG in csv file uploading
#1

[eluser]rampelli[/eluser]
Hi
when i tried to upload csv file using CI 1.7.1 ..
i am able to upload it in IE , Chrome but unable to upload it using Firefox 3.5.3
showing an error "The filetype you are attempting to upload is not allowed."
can any one fix this problem as soon as possible
#2

[eluser]imn.codeartist[/eluser]
post your upload script, there might be some case sensitive extension issue
#3

[eluser]rampelli[/eluser]
thanks for your reply below is my upload script

Code:
$config['upload_path'] = './uploadpath/csv/';
        $config['allowed_types'] = 'csv';
        $config['max_size']    = '5000';
        $this->CI->load->library('upload', $config);
    $this->CI->upload->do_upload('file')
#4

[eluser]Unknown[/eluser]
I am having the same problem as is described here. File uploads of type csv are working fine in Internet Explorer and Google Chrome, but not Firefox.

I found these other threads that seemed relevant, but they do not seem to solve the problem:
http://ellislab.com/forums/viewthread/86033/#554404
http://codeigniter.com/bug_tracker/bug/4906/

The csv file i'm trying to upload is simple:

"(609)555-1221", "A. Smith"
"(609)555-1222", "R. Arroya"

Any ideas ?
#5

[eluser]colinbird[/eluser]
also having this issue

CI 1.7.2
#6

[eluser]BrianDHall[/eluser]
In mimes.php:

Code:
'csv'    =>    array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel')

I'd be utterly shocked if you check the mime-type that the browser that isn't working is submitting that it won't be a part of this list.

I had this problem with flash uploader - after initial oddness in how mime types are submitted via flash, I found different browsers sometimes had their own twist on what flash said the mime type was. The only solution was going through and checking mimes on every browser version I had to see what all the crazy types reported were.
#7

[eluser]colinbird[/eluser]
I ended up making a sub-class of upload that overrode the is_allowed_filetype() method

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once("Upload.php");

class Csvupload extends CI_Upload{

function Csvupload($props = array())
{
parent::CI_Upload($props);
}

function is_allowed_filetype()
{
$data = $this->data();
return $data["file_ext"] == ".csv";
}
}
#8

[eluser]stumped2010[/eluser]
Also having the same issue with CSV file upload in FF3. Unfortunately, I'm a big time newbie to all this, and a lot of the stuff folks are writing is a mystery. Is there anyplace around here that provides a step-by-step correction to this issue? I find bits and pieces of conversation threads, but nothing comprehensive that says "replace X in line y with z".
#9

[eluser]Mirage[/eluser]
The Good
Open config/mimes.php, find the csv extension (around line 13) and add 'text/x-csv' to the array and viola. You're in business.

The Bad
The problem is that the mimetype for csv files isn't resolved properly. It's not a CI bug per-se.

When browser submit a form of type 'multipart/form-data' they set a content-type header for each submitted file. This in turn is processed by PHP into the $_FILES array 'type' key.

CI validates allowed file types, by cross-referencing this 'type' key with values stored in it's own dictionary of mimes ( config/mimes.php ). Ironically - the upload class, uses the file-extension to look up the possible list of mimes.

For CSV files, FF submits a mime-type of 'text/x-csv'. Which is not listed in CI's dictionary for the 'csv' extension. Ergo - it will never be allowed.

The ugly
If you upgrade your CI environment at some point in the future, you may replace mimes.php with the distro and if this mime-type wasn't rolled into the distro, you'll have some problems and fix it again.

I really do not understand WHY CI insists on using mime-types for comparison, especially when 'allowed_types' is a set of of extensions. Clearly, the browsers determine mime-type by extension. So simply testing the extension would suffice. Whether a gif is actually a gif or a csv is a csv can't be proven in either case. But one thing is a given: THE FILE EXTENSION. No guessing there.

It's simply confusing to be allowing a type by extension, but having the actual validation happen against something else. I'd vote for the validation to happen against the extension, as collinbird implemented with his class override. I just hate modifying the core for these 'fix' things. That's not what class extension are meant to be for. And it's increasingly hard to track all the 'fixes' across CI releases. Frustrating actually.

In all fairness, FF doesn't impress me either with yet another mime-type for csv. Just have a look at the list of mimes already put into CI. Good Lord! Mimes are no more accurate or predictable than extensions.

Cheers,
m
#10

[eluser]stumped2010[/eluser]
That's awesome. Thanks for that.
I also found a post elsewhere on this site that offered a bit of a fix to the Upload.php file. I amended the file with the new bit of code, and uploaded it here for anyone that is interested. Commented as well.




Theme © iAndrew 2016 - Forum software by © MyBB