CodeIgniter Forums

Full Version: Upload filetype not allowed??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3

El Forum

[eluser]123wesweat[/eluser]
Hi,

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

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

How can i fix this??

btw this is my htaccess
Code:
<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>

<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
</IfModule>

El Forum

[eluser]rogierb[/eluser]
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:-)

El Forum

[eluser]123wesweat[/eluser]
hmm,


mimes.php reads
Code:
'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
Code:
$uploadFile = $this->upload->data();
                echo 'test: '.mime_content_type($uploadFile['file_name']);

Any other suggestions??

El Forum

[eluser]hqhdn[/eluser]
Quote:How can i check the mime type of a file i am uploading???

You can try to use:

Code:
$_FILES[name]['type']

El Forum

[eluser]rogierb[/eluser]
You can echo the upload array with $this->upload->data();

An explanation of the array can be found in the userguide.
http://ellislab.com/codeigniter/user-gui...ading.html

El Forum

[eluser]hqhdn[/eluser]
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

Code:
// 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.
         */
        $this->set_image_properties($this->upload_path.$this->file_name);

El Forum

[eluser]rogierb[/eluser]
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?

El Forum

[eluser]123wesweat[/eluser]
this is the error i get
Code:
Array ( [error] =>

The filetype you are attempting to upload is not allowed.
)

El Forum

[eluser]rogierb[/eluser]
hmm, weird.

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

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

El Forum

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

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

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

All look ok to me.
Pages: 1 2 3