no

How to Fix Codeigniter File Uploading Class Fails

Yes it does, and it throws this error "The filetype you are attempting to upload is not allowed." even though you have specified y...

Yes it does, and it throws this error "The filetype you are attempting to upload is not allowed." even though you have specified your file in the class's "allowed_types" property.

Solution:
1.) Overwrite the Upload class by creating a new My_Upload.php file in your application/libraries directory

2.) Paste the following code, notice I have added the "if($this->is_image())" condition, since the code should only check the image size if the filetype is image.

class My_Upload extends CI_Upload {
function is_allowed_filetype()
{
if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
{
$this->set_error('upload_no_file_types');
return FALSE;
}

$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');

foreach ($this->allowed_types as $val)
{
$mime = $this->mimes_types(strtolower($val));

// Images get some additional checks
if (in_array($val, $image_types))
{
if($this->is_image()) {
if (getimagesize($this->file_temp) === FALSE)
{
return FALSE;
}
}
}

if (is_array($mime))
{
if (in_array($this->file_type, $mime, TRUE))
{
return TRUE;
}
}
else
{
if ($mime == $this->file_type)
{
return TRUE;
}
}
}
return FALSE;
}
}

Related

web 7651334939996388952

Post a Comment Default Comments

Outsourcing

Are you looking for freelancers in the Philippines? Get in touch.

Donations

If you like what I do, you can support this channel by buying me a coffee. I would be grateful for your contribution! Your donations will help me create more FREE online courses and learning materials for programmers and remote workers.

item