2

I have a small PHP script that fixes some errors in Subtitle Workshop .srt-files. It works fine, but i have a problem validating .srt-files MIME types. Here's a part of the code in question:

if ( $_FILES['file']['type'] != 'text/plain' &&
$_FILES['file']['type'] != 'application/x-subrip') {    
$error .= '<p>MIME type is not allowed!</p>';
}

.srt-files are actually plain text files. When i upload subtitles in .txt-file my script works fine. But when i try to upload the same file with .srt extension i get "MIME type is not allowed!" error. 'application/x-subrip' (found it here) is obviously a culprit. But what should i use instead? Thanks in advance!

user2696785
  • 143
  • 2
  • 3
  • 11

1 Answers1

2

I don't think you could do this validation. Plain text file may have a lot of mimetypes, like "text/plain", "application/octet-stream", "text/str", etc. You could do a white list, but also need to do another type of validation, maybe by content, or using a library.

Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
  • Thanks! I already have some other type of validations as well (file size and extensions). I removed MIME type validation now and replaced it with the validation based on file content (using some regex). – user2696785 May 10 '16 at 22:13