Welcome Guest, Not a member yet? Register   Sign In
Quotes in mime type when uploading
#1

[eluser]Michael DOUBEZ[/eluser]
Hello,

When trying to upload a file, the mime type is not recognized because of quotes under FF3 (itworks under IE).

I have already filled a bug report:
http://codeigniter.com/bug_tracker/bug/p...under_ff3/
And I have been prompted by Derek Allard to start this thread.

To illustrate the problem, I have setup a pristine Code Igniter 1.6.2 on
http://michael.doubez.free.fr/index.php/test

The test is trying to upload a file with .bin extension with FF3.
The controller used (more or less) is:
http://michael.doubez.free.fr/test.txt

The output of:
echo $this->upload->display_errors();
echo ol($this->upload->data());
is
<<<
The filetype you are attempting to upload is not allowed.

1. test.bin
2. "application/octet-stream"
...
>>W
See the quotes in the mime type reporting.

Note: I have changed my mimes.php file
'bin' => 'application/octet-stream',


Cheers
#2

[eluser]Derek Allard[/eluser]
Thanks Micael.

Can you share the file with us that you're tying to upload? I haven't seen this behaviour, and have used FF3 for CI uploading a lot.
#3

[eluser]Michael DOUBEZ[/eluser]
I can but it will not help a lot, it is an empty file with .bin extension.
The same happens with a real binary file which is encrypted (and thus unrecognizable with magic pattern).

As I have mentioned in the but report, I have not had this behavior at first until I tried to get it back (with a force_download). FF3 proposed me to open it with IZarcBin but I simply save it. From that point on, I could no longer upload a file.

However, it is not necessarily a CodeIgniter issue (the same works in IE). But since the quotes are not striped, the mime type is not matched and I don't know what the standard(RFC?) says about the format of mime-type in $_FILES[]['type'].

Here is the ethereal dump of the transaction (i could not attach it):
POST /index.php/test/index HTTP/1.1
Host: michael.doubez.free.fr
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://michael.doubez.free.fr/index.php/test/index
Cookie: __utma=172764660.2276437954795728600.1212670172.1212670172.1212670172.1; __utmz=172764660.1212670172.1.1.utmcsr=adsl.free.fr|utmccn=(referral)|utmcmd=referral|utmcct=/compte/console.pl
Content-Type: multipart/form-data; boundary=---------------------------162821245525734
Content-Length: 313

-----------------------------162821245525734
Content-Disposition: form-data; name="testfile"; filename="test.bin"
Content-Type: "application/octet-stream"


-----------------------------162821245525734
Content-Disposition: form-data; nam
e="upload"

Upload
-----------------------------162821245525734--

HTTP/1.1 200 OK
Date: Thu, 24 Jul 2008 07:19:59 GMT
Server: Apache/ProXad [May 5 2008 17:44:06]
X-Powered-By: PHP/5.1.3RC4-dev
Connection: close
Content-Type: text/html



&lt;html&gt; &lt;body&gt;
<h1>File upload</h1><BIG>Uploading failed</BIG><br /><p>The filetype you are attempting to upload is not allowed.</p><ol>
<li>test.bin</li>
<li>\"application/octet-stream\"</li>
<li>/mnt/138/sda/d/1/michael.doubez/upload/</li>
<li>/mnt/138/sda/d/1/michael.doubez/upload/test.bin</li>
<li>test</li>
<li></li>
<li>.bin</li>
<li>0</li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ol>
<big><b>Test files</b></big><br />&lt;form action="http://michael.doubez.free.fr/index.php/test/index" method="post" enctype="multipart/form-data"&gt;Upload a new firmware: &lt;input type="file" name="testfile" value="" maxlength="500" size="20"&gt;
&lt;input type="hidden" name="upload" value="Upload" /&gt;&lt;/form>
<br />
#4

[eluser]Derek Allard[/eluser]
Confirmed (code below). Curse you for making me load Windows Wink

I works find on FF3 on Mac, and every other browser. It certainly appears to be a Firefox bug. I did a quick search of bugzilla, and didn't notice anything reported. I'd encourage you to do a more thorough search, and post it if it isn't there.

I'm going to label the bug external, since there's nothing we can do here, and Firefox seems to be playing by its own rules.

Sincere thanks for reporting. I think for now you'll need to either add that mime to your allowable types, or do a user-agent detection trick.

Thanks.

Code:
&lt;?php
class Tester extends Controller {

    function index()
    {
        $this->load->helper('form');
        echo form_open_multipart('tester/do_that_upload');
        echo form_upload('userfile');
        echo form_submit(array('value' => 'upload that bin file'));
        echo form_close();
    }

    // --------------------------------------------------------------------

    function do_that_upload()
    {
        $config['upload_path'] = './img/logo/'; // happens to be my test upload path
        $config['allowed_types'] = 'bin';    
        $config['max_size']    = '500';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            echo $this->upload->display_errors();
        }
        else
        {
            echo "worked";
        }
        
    }

}
?&gt;
#5

[eluser]Michael DOUBEZ[/eluser]
To tell you the truth, I'll rather modify the Upload class as shown in the bug report and keep the patch somewhere for future update.

Looking into RFC2045, the EBNF doesn't seem to allow quotes for mime type (only for the parameters).

Cheers,
#6

[eluser]Derek Allard[/eluser]
Yup, fair enough. Browser bugs can be a pain to work around, but this one seems comparatively minor (I'm looking at you Internet Explorer!) Smile

Thanks for your work here Michael.
#7

[eluser]phazei[/eluser]
I'm not sure what version if FF he was running to get that glitch with the quotes around the mime type...

I'm working on a new site and found the same problem. I went back to some old sites that used the same upload, and it started giving me the "The filetype you are attempting to upload is not allowed." error as well.

Only difference is I recently upgraded to FF3.1b3.

Had no such problems with FF3.1b2.
#8

[eluser]Michael DOUBEZ[/eluser]
If I remember correctly, it was working fine but after an error in the mime-type, it went all wrong and I could no longer upload. I have not tried to clear the cache or use another FF. It was really a strange bug.

For test, you may use another FF3 on your computer (I may suggest to download it from PortableApps such that you will have a pristine install of FF).
#9

[eluser]Unknown[/eluser]
I am having the same problem with uploading a CSV file with FF 3.0.10 on OSX. With safari works without problems.
#10

[eluser]k00k[/eluser]
[quote author="lebada" date="1242870634"]I am having the same problem with uploading a CSV file with FF 3.0.10 on OSX. With safari works without problems.[/quote]


Same thing here. I seem to have gotten around it just now by changing the 'csv' mime type to:

'csv' => 'text/plain'


Not sure of any ramifications of that yet though.




Theme © iAndrew 2016 - Forum software by © MyBB