1. Home
  2. Products
  3. Sportdata Cloud Office
  4. osTicket
  5. Fix file upload error (http 500, undefined)

Fix file upload error (http 500, undefined)

Due to a bug in PHP 8 the fileinfo() method returns invalid values, leading OSTicket to not let you upload e.g. ZIP or CSS files.

To fix this edit the isValidFile() function in include/class.forms.php :

static function isValidFile($file) {
  // Make sure mime type is valid 
  
  // var_dump($file['type']);
  // var_dump(FileObject::mime_type($file['tmp_name']));
  // var_dump(phpversion());
  
  if (!empty($file['type']) &&  
    strcasecmp(FileObject::mime_type($file['tmp_name']),              
    $file['type']) !== 0){

    // BUG fileinfo() with ZIP file in PHP 8.0
    if ( version_compare(PHP_VERSION, '8.1.0', '<') && (
      (preg_match("/zip/", $file['type']) && 
        strcasecmp(FileObject::mime_type($file['tmp_name']), 
          "application/octet-stream" == 0))
      || (preg_match("/css/", $file['type']) && 
        strcasecmp(FileObject::mime_type($file['tmp_name']), 
          "text/plain" == 0) )
    )){
      ; // noop
    } else return false;

  }

  // Check invalid image hacks
  if ($file['tmp_name']
    && stripos($file['type'], 'image/') === 0
    && !exif_imagetype($file['tmp_name']))
    return false;

  return true;
}
Updated on July 25, 2023

Was this article helpful?

Related Articles