Exemple #1
0
 /**
  * @param $data - the raw data to check
  * @return FileInformationResults
  * @throws \Exception
  */
 public function get_data_information(&$data)
 {
     if (!InstanceHolder::fileinfo_enabled()) {
         throw new \Exception("FileInfo extension not available");
     }
     //Grab the mime type and encoding
     $finfo = finfo_open(FILEINFO_MIME);
     $full_mime = finfo_buffer($finfo, $data);
     $mimex = explode(";", $full_mime);
     $type = $this->getArrayValue($mimex, 0);
     $full_encode = $this->getArrayValue($mimex, 1);
     $full_encode = $full_encode === null ? '' : $full_encode;
     $encodex = explode('=', $full_encode);
     $encoding = $this->getArrayValue($encodex, 1);
     //Grab the file size
     $size = strlen($data);
     //Grab the recommended extension
     $recommended_extension = $this->provide_recommended_file_extension($type);
     return new FileInformationResults($type, $encoding, $recommended_extension, $size);
 }