header(“Content-type: text/css”); is working in Firefox and Chrome, but in Internet Explorer 9 it shows up as 'text/html'

前端 未结 8 1063
时光取名叫无心
时光取名叫无心 2020-12-01 09:12

header(\"Content-type: text/css\"); works in Firefox, Chrome and other, but not in Internet Explorer 9. I am not sure what\'s up.

In Chrome an

8条回答
  •  悲&欢浪女
    2020-12-01 09:53

    Recently I had a problem like this for myself too. Nasty debugging is all I can tell about this. Not sure if this might help you people, but I hope it will. Cut to the chase.

    Internet Explorer uses something called Mime-type sniffing, which simply reads 200 Bytes of THE FILE header.

    I had a PHP script which had to return different video file (with data - the whole file) dependent on the parameter it had been supplied with.

    My video request example: get-video.php?id=here_goes_the_id

    $file = ''; // Get the video file path
    if (is_file($file)) {
        header("Content-Type: video/mp4");
        header("Content-Length: " . filesize($file));
        readfile($file);
    }
    exit(); // This is the turnaround
    

    You have to suspend your script immediately after it sends the file data. This prevents the IE Mime-type sniffing.

    Hope it helps.

提交回复
热议问题