Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter: “The filetype you are attempting to upload is not allowed.”
#11

[eluser]jiolasa[/eluser]
I should've known.. work at it for an hour, post, and then immediately find the answer.

The answer to my problem was with MIME types--I'll leave this comment up here in case it is related. My CSV was returning with a MIME type of text/plain instead of any of the many acceptable CSV MIME types, so I just added text/plain to the csv entry in application/config/mime.php.

The weird thing is, this wasn't a problem with 2.0.2. I reverted to 2.0.2 right now and it showed my file's MIME type as text/csv, so something must've changed in the way it reads file types between 2.0.2 and 2.1.
#12

[eluser]Unknown[/eluser]
[quote author="thisischris" date="1332668939"]I have also recently gotten that error. I think someone forget to select a file and hit upload anyway. Now each time it gives me the error.

I found this in the log: ERROR - 2012-03-25 11:22:36 --> Severity: Notice --> Undefined index: tmp_path /homepages/14/xxxx/htdocs/xxx/system/libraries/Upload.php 1058

which is this block: [codeif (DIRECTORY_SEPARATOR !== '\\' && function_exists('exec'))
{
$output = array();
@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);
if ($return_code === 0 && strlen($output[0]) > 0) // A return status code != 0 would mean failed execution
{
$this->file_type = rtrim($output[0]);
return;
}
}[/code]

This line basically: @exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);

It works perfectly in my localhost (windows) however the server is definitely linux.[/quote]

I ran across the same problem on my Mac. I print_r()'d $file and found that there was no 'tmp_path' element in that array, only 'tmp_file'. I replaced 'tmp_path' with 'tmp_file' and it worked.

Maybe Windows uses 'tmp_file' and Linux/Unix use 'tmp_path'? To get it to work on both Windows and Linux, you may need to write some code that checks for both 'tmp_file' and 'tmp_path' and uses whichever one is there.

I'm new to CodeIgniter--does anyone know how I can report this as a possible bug?
#13

[eluser]Narf[/eluser]
This is an already fixed bug and there's multiple topics on that.

https://raw.github.com/EllisLab/CodeIgni...Upload.php
#14

[eluser]Unknown[/eluser]
The problem is with mime type only, you can trace your flow in the file
system\libraries\Upload.php ---- public function is_allowed_filetype($ignore_mime = FALSE)
the only way this function return a true value is if

1. $this->file_type exactly matches $mime.
2. $this->file_type is present in the array $mime.

you can check this way where does the problem lies.

One strange observation, same extension file(.doc) returns different mime types on different servers.
#15

[eluser]matt2012[/eluser]
I was having a problem with doc it turned out my server was seeing it as rtf.

This fixed it
in config/mimes.php

from
Code:
'doc' => 'application/msword',

to

Code:
'doc' => array('application/msword','text/rtf'),
#16

[eluser]Unknown[/eluser]
PHP has a bug when detecting mime-types using finfo_file().
https://bugs.php.net/bug.php?id=55182

Unfortunately, the Upload class relies on this buggy function in _file_mime_type().

For me, it's seeing a csv file as text/plain.
#17

[eluser]Narf[/eluser]
It's good to see at least somebody knows that there's nothing more that can be done on CodeIgniter's end, but as I commented on the linked bug report - it's not fair to blame it all on PHP either. Even if there is a bug in file_info(), chances are that it would be relevant in 1% of the cases.
#18

[eluser]ExpediteWebsys[/eluser]
I was using previous codeigniter version for my website. Even i was facing issue while uploading the file... issue was same as described by the post owner. I then downloaded Codeigniter 2.1.2 version and replaced upload.php library with the new updated one. This resolved this issue. There was a bug in the pervious version.

Copy it in system\libraries folder. Make sure you keep the back up of the original file.

Have a great time. Smile
Thanks.
#19

[eluser]Unknown[/eluser]
Check the mime file name in your xampp/apache/conf/ folder
Check if it is 'mime' or 'mimes'
Now open the Upload.php file in your system/libraries folder in codeigniter
Go to line 949
Replace the file name 'mimes' to 'mime' as follows

public function mimes_types($mime)
{
global $mimes;

if (count($this->mimes) == 0)
{
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mime.php')Wink
{
include(APPPATH.'config/'.ENVIRONMENT.'/mime.php');
}
elseif (is_file(APPPATH.'config/mime.php')Wink
{
include(APPPATH.'config//mime.php');
}
else
{
return FALSE;
}

$this->mimes = $mimes;
unset($mimes);
}

return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime];
}
Now stop and restart xampp.....

Differences in the xampp and codeigniter versions or standards may be the problem. Hope this works.....;-)
#20

[eluser]skunkbad[/eluser]
[quote author="thecompleteprogrammer" date="1347692449"]Check the mime file name in your xampp/apache/conf/ folder
Check if it is 'mime' or 'mimes'
Now open the Upload.php file in your system/libraries folder in codeigniter
Go to line 949
Replace the file name 'mimes' to 'mime' as follows

public function mimes_types($mime)
{
global $mimes;

if (count($this->mimes) == 0)
{
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mime.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/mime.php');
}
elseif (is_file(APPPATH.'config/mime.php'))
{
include(APPPATH.'config//mime.php');
}
else
{
return FALSE;
}

$this->mimes = $mimes;
unset($mimes);
}

return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime];
}
Now stop and restart xampp.....

Differences in the xampp and codeigniter versions or standards may be the problem. Hope this works.....;-)
[/quote]

This is no solution. The filename in application/config IS mimes.php, not mime.php. You should also properly extend the Upload class, and not make changes directly to core files.




Theme © iAndrew 2016 - Forum software by © MyBB