Created
September 23, 2021 08:28
-
-
Save slav123/d7dfdd767c70e4856f332da5a111265e to your computer and use it in GitHub Desktop.
Extended / Overloaded CI-Upload Class to handle Flash-Form-Uploaded Images via Application/octet-stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Extended / Overloaded CI-Upload Class to handle Flash-Form-Uploaded Images via Application/octet-stream | |
* | |
*/ | |
if (!defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Extends the CodeIgniter Upload-Class | |
*/ | |
class MY_Upload extends CI_Upload { | |
/** | |
* Verify that the filetype is allowed | |
* | |
* @return bool | |
*/ | |
public function is_allowed_filetype($ignore_mime = FALSE) | |
{ | |
if ($this->allowed_types == '*') | |
{ | |
return TRUE; | |
} | |
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)) | |
{ | |
$gis = getimagesize($this->file_temp); | |
if ($gis === FALSE) | |
{ | |
return FALSE; | |
} else { | |
$this->file_type = $gis['mime']; | |
} | |
} | |
if ($ignore_mime === TRUE) | |
{ | |
return TRUE; | |
} | |
$mime = $this->mimes_types($ext); | |
if (is_array($mime)) | |
{ | |
if (in_array($this->file_type, $mime, TRUE)) | |
{ | |
return TRUE; | |
} | |
} | |
elseif ($mime == $this->file_type) | |
{ | |
return TRUE; | |
} | |
return FALSE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment