json抛出无效的UTF-8序列

I have one ec2 server with php 5.3 and with 2 virtual hosts: 1 dev and 1 live.

On the dev if someone uploads a file with a bad UTF-8 it ignores the error and it just doesn't convert the variable.

On the live host it throws this error and stops the php script:

Message: json_encode(): Invalid UTF-8 sequence in argument.

Any reason I am getting mixed results on the same server?

Option 1:

Perhaps you do not have error reporting on dev, but you do on live. To test this theory all you need to do is turn error_reporting off.

error_reporting(0);
ini_set('display_errors', 0);

Option 2:

You could try converting the 'file' to UTF-8 automatically using mb_convert_encoding().

$file = mb_convert_encoding($file, 'UTF-8');
echo json_encode($file);