Welcome Guest, Not a member yet? Register   Sign In
Upload filetype not allowed??


i have set these filetypes as allowed
$config['allowed_types'] = 'doc|docx|gif|jpeg|pdf|jpg|rtf|txt|text';

filetypes .doc .docx jpg gif jpeg all upload correct
.pdf .txt .text .rtf doesn't upload???

How can i fix this??

btw this is my htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    ### Canonicalize codeigniter URLs
    ### http://farinspace.com/2009/06/codeigniter-htaccess-file/
    ### http://ellislab.com/forums/viewthread/136195/

    # If your default controller is something other than
    # "welcome" you should probably change this
    #RewriteRule ^(main(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(main(/index)?|index(\.php)?)/$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php

Check the mimes.php. See what types are set for .txt .rtf etc.
Then check your files to see if the mimes match.

If they are not in mimes.php, add them:-)


mimes.php reads
'txt'    =>    'text/plain',
                'text'    =>    'text/plain',
'rtf'    =>    'text/rtf',

'pdf'    =>    array('application/pdf', 'application/x-download'),

looks good to me.

How can i check the mime type of a file i am uploading???

I tried
$uploadFile = $this->upload->data();
                echo 'test: '.mime_content_type($uploadFile['file_name']);

Any other suggestions??

Quote:How can i check the mime type of a file i am uploading???

You can try to use:


You can echo the upload array with $this->upload->data();

An explanation of the array can be found in the userguide.

In this case: $this->upload->data() is NULL because the file doesn’t uploaded. You only can get information from $this->upload->data() until the file was uploaded on server.

You can see it in library/Upload.php

// Set the uploaded data as class variables
        $this->file_temp = $_FILES[$field]['tmp_name'];        
        $this->file_name = $this->_prep_filename($_FILES[$field]['name']);
        $this->file_size = $_FILES[$field]['size'];        
        $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']);
        $this->file_type = strtolower($this->file_type);
        $this->file_ext     = $this->get_extension($_FILES[$field]['name']);

         * Set the finalized image dimensions
         * This sets the image width/height (assuming the
         * file was an image).  We use this information
         * in the "data" function.

The file type is checked after that part of code. I guess should be filled...

What error message do you get when uploading the files?

this is the error i get
Array ( [error] =>

The filetype you are attempting to upload is not allowed.

hmm, weird.

What you can do is temporarily edit Upload.php
$this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']);
echo $this->file_type

Just to see what $_FILES produces and what file_type CI creates.

hmm, .txt gives
Array ( [userfile] => Array ( [name] => test.txt [type] => text/plain [tmp_name] => /tmp/phpFua8uJ [error] => 0 [size] => 92 ) ) text/plain

.rtf gives
Array ( [userfile] => Array ( [name] => test_upload.rtf [type] => text/rtf [tmp_name] => /tmp/phptEheEf [error] => 0 [size] => 2207 ) ) text/rtf

.pdf gives
Array ( [userfile] => Array ( [name] => route.pdf [type] => application/pdf [tmp_name] => /tmp/php6b4ubb [error] => 0 [size] => 84853 ) ) application/pdf

All look ok to me.

Theme © iAndrew 2016 - Forum software by © MyBB