Alternative to file_get_contents?

前端 未结 6 827
死守一世寂寞
死守一世寂寞 2020-12-04 23:44
$xml_file = file_get_contents(SITE_PATH . \'cms/data.php\');

The problem is that a server has URL file-access disabled. I cannot enable it, its a h

6条回答
  •  感动是毒
    2020-12-05 00:12

    If the file is local as your comment about SITE_PATH suggest, it's pretty simple just execute the script and cache the result in a variable using the output control functions :

    function print_xml_data_file()
    {
        include(XML_DATA_FILE_DIRECTORY . 'cms/data.php');
    }
    
    function get_xml_data()
    {
        ob_start();
        print_xml_data_file();
        $xml_file = ob_get_contents();
        ob_end_clean();
        return $xml_file;
    }
    

    If it's remote as lot of others said curl is the way to go. If it isn't present try socket_create or fsockopen. If nothing work... change your hosting provider.

提交回复
热议问题