• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Upload Class - MIME type detection error - 2.1.0

#11
[eluser]kanhai[/eluser]
I did some debugging and found that in the is_allowed_filetype function in line 624 for a csv file the $this->file_type returns text/plain where as when I check in the $_FILES["file"]["type"] it returns text/csv

I added the text/plain in the csv array in the application/config/mime.php file and it started working,

what I am wondering is that is this a bug? and should I file a bug report for this?

There are two possible solutions
1. Find out why there is this difference in these two and fix it (this feels the correct way to solve this)
2. just add text/plain in the csv array in mimes.php file (this seems the easy way, not sure if this is correct).

I could file a bug and suggest that we should add the text/plain in the csv array anyway in the next build.

Kanhai Chhgani

#12
[eluser]zwadder[/eluser]
I had the same problem and the suggested solutions didn't work. I had reports that DOCX, PPT and some other extensions wouldn't upload. I found out that all of these files had a MIME type of "application/zip", obviously the came out of a zipped archive, after making an array for the docx type in adding 'application/zip' to the docx mime type did the trick. Then I did the same for the other types and it all worked.
I think using this can be tricky because every file can be uploaded by first zipping it and unzipping it en renaming the extension to docx.

#13
[eluser]Musaddiq Khan[/eluser]
Replace function is_allowed_filetype() in sysetem/libraries/Upload.php, It has worked for me.


Code:
public function is_allowed_filetype($ignore_mime = FALSE)
{
  if ($this->allowed_types == '*')
  {
   return TRUE;
  }
  //echo '$this->allowed types==>'.$this->allowed_types;
  if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
  {
   $this->set_error('upload_no_file_types');
   return FALSE;
  }

  $ext = strtolower(ltrim($this->file_ext, '.'));

  if ( ! in_array($ext, $this->allowed_types))
  {
   return FALSE;
  }

  // Images get some additional checks
  $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');

  if (in_array($ext, $image_types))
  {
   if (getimagesize($this->file_temp) === FALSE)
   {
    return FALSE;
   }
  }
  
  if ($ignore_mime === TRUE)
  {
   return TRUE;
  }
  $mime = $this->mimes_types($ext);
  
  if ($ext == 'png')
  {
   $mime[] = $ext;
   $this->file_type = $ext;
  }
  if (is_array($mime))
  {
   if (in_array($this->file_type, $mime, TRUE))
   {
    return TRUE;
   }
  }
  elseif ($mime == $this->file_type)
  {
    return TRUE;
  }

  return FALSE;
}

#14
[eluser]Unknown[/eluser]
thank you very much,it really help me a lot

#15
[eluser]Stu Green[/eluser]
For anyone still struggling with this, the fix in 2.1.2 is not good enough.

You also need to add:

Code:
application/x-zip

To the array in the docx mime types too.

#16
[eluser]Unknown[/eluser]
Just ran into this.

If your php version is >= 5.3, make sure you have the php module finfo installed, otherwise the class will fall back on the dirty hack at the bottom which wasn't working for me, resulting in a fail no matter what because it wasn't working properly and leaving no access to the file mime type.


#17
[eluser]corescript[/eluser]
All my upload are working except .flv files

what wrong?

anybody can help?


thanks

#18
[eluser]Unknown[/eluser]
I had the same issue when uploading csv files and the following solution worked for me.

[quote author="kanhai" date="1343032979"]I did some debugging and found that in the is_allowed_filetype function in line 624 for a csv file the $this->file_type returns text/plain where as when I check in the $_FILES["file"]["type"] it returns text/csv

I added the text/plain in the csv array in the application/config/mime.php file and it started working,

what I am wondering is that is this a bug? and should I file a bug report for this?

There are two possible solutions
1. Find out why there is this difference in these two and fix it (this feels the correct way to solve this)
2. just add text/plain in the csv array in mimes.php file (this seems the easy way, not sure if this is correct).

I could file a bug and suggest that we should add the text/plain in the csv array anyway in the next build.

Kanhai Chhgani[/quote]


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.