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]rogierb[/eluser]
Yeah, it looks okay, but is doesnt work... So either $this->mimes_types is off or some other random error.

Can you debug is_allowed_filetype()?
See why it is returning a FALSE?

El Forum

[eluser]123wesweat[/eluser]
hmmm,

in Upload.php in function is_allowed_filetype() i added
Code:
foreach ($this->allowed_types as $val)
        {
            echo $val;

and when i upload a jpg it returns
Code:
doc
docx
gif
jpeg

when i try to upload a .txt
Code:
doc
docx
gif
Array ( [error] =>

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

Now the strange thing is when i use
Code:
$config['allowed_types'] = 'txt|text';
it does upload the .txt file.

Is there a particular order we should follow??

El Forum

[eluser]123wesweat[/eluser]
Ok this is strange

this seems to be a working array
Code:
$config['allowed_types'] = 'doc|docx|pdf|txt|text|rtf|jpg|gif';

not working
Code:
$config['allowed_types'] = 'doc|docx|gif|jpeg|pdf|jpg|rtf|txt|text';

El Forum

[eluser]rogierb[/eluser]
The order shouldn't matter.

Can you debug set_allowed_types() to see what $types and $this->allowed_types are?

El Forum

[eluser]Craig300[/eluser]
I had a similar problem and found that if I put the pdf file extension at the beginning of that list, it seemed to work.

Eg: pdf|doc|docx etc

El Forum

[eluser]Vangelis B[/eluser]
[quote author="rogierb" date="1266418911"]The order shouldn't matter.

Can you debug set_allowed_types() to see what $types and $this->allowed_types are?[/quote]

Unfortunately the people are right. The order does matter. The reason is that the upload library first does a check for images before check in the config/mimes.php. The library checks to see if the temp file (during the upload) returns an image size. Unfortunately it does the check for files that are not images as well. Obviously this is a bug.

A temporary solution is to comment the following lines in system/libraries/upload.php

Code:
if (in_array($val, $image_types)){
  if (getimagesize($this->file_temp) === FALSE){
    return FALSE;
  }
}

they are around line 565

I'll submit this bug and lets hope that CI devs will come up with a fix in the next CI version.

El Forum

[eluser]crojac[/eluser]
See my post on the subject

http://ellislab.com/forums/viewthread/146338/

El Forum

[eluser]Phil Sturgeon[/eluser]
This has been fixed in CodeIgniter 2.0.

El Forum

[eluser]Unknown[/eluser]
As far as RTF goes, this can be a tricky mime-type to deal with. In general, the mime-type for RTF is 'application/rtf' and NOT 'text/rtf' (according to w3schools and good ol' M$). So right off the hop, Codeigniter has a possibly incorrect mime-type listed.

HOWEVER, some products stamp the mime-type as 'application/msword' for RTF files. We had to change the 'rtf' entry in the mimetypes array (located in /system/application/config/mimes.php) to be 'application/msword' to get our users' RTF files uploading correctly. This may have something to do with the way the RTF file type is defined on their Windows XP computers, I am not 100% certain.

WHEN IN DOUBT, install the Live HTTP Headers Add-On in Firefox, it will let you know what the browser is thinking in terms of what the file type is that is being uploaded.

El Forum

[eluser]Ossama Khayat[/eluser]
I suffered trying to fix this, and after some debugging I found the solution, which is what in the patch for 2.0.
Why isn't this also fixed for 1.7.2?
Pages: 1 2 3