I am aware that the correct MIME type fo json files is applicattion/json
as may be confirmed by this post What is the correct JSON content type?.
However, I wonder why my PHP installation is returning text/plain
. I need to test for the correct mime before parsing the json file.
I have the following code
$fileinfo = new finfo();
$fileType = $fileinfo->file( $_FILES['tmp_name'], FILEINFO_MIME_TYPE );
in which $fileType
returns text/plain
instead of applicattion/json
.
Again, $_FILES['type']
returns application/octet-stream
instead of applicattion/json
.
What am I missing?
Edit
I am sending the file through jQuery ajax:
var formData = new FormData( $(form)[0] );
var jsonFile = $( 'input:file[name=contents]', form ).get(0).files[0];
formData.append( 'jsonFile', jsonFile );
$.ajax({
type: 'POST',
url: 'url',
data: formData,
dataType:'json',
enctype : 'multipart/form-data',
processData: false,
contentType : false,
encode:true,
})