Get Content-Type of requested url in php

后端 未结 3 1816
不知归路
不知归路 2020-12-11 10:01

Using php how would I be able to define the variable $type into the content-type of http://www.example.com

For example: $type

3条回答
  •  时光取名叫无心
    2020-12-11 10:18

    Sometimes get_header return wrong values becouse it read http headers, but not file. It should be better use finfo:

    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $type = $finfo->buffer(file_get_contents($link));
    

提交回复
热议问题