file_get_contents method return some value with st

2019-08-18 06:09发布

Getting Strange response from file_get_contents Method in php

$binaryfile = file_get_contents('https://xyz.abc.ee/api/file.php?hash='.$final_hash_std_cert.'&action=getFile&name='.$cert, false, stream_context_create($stream_opts));
echo $binaryfile;

on ajax side i'm doing this :

productCert = $(this).attr('data-cert');
$.ajax({
    type: "POST", // use $_POST method to submit data
    url: my_ajaxurl, // where to submit the data
    data: {
        action     : 'load_cert_action',
        cert_url : productCert, // PHP: $_POST['first_name']
    },
    success:function(data) {
        console.log(data); // here i'm getting strange output
        //window.location.assign(data);
        // var pdfWindow = window.open("");
        // pdfWindow.document.write(data)
    },
    error: function(errorThrown){
        console.log(errorThrown); // error
    }
});

Getting this response in console :

%PDF-1.5 %���� 5 0 obj <>stream H���yTSw�oɞ����c [���5, �� �BHBK!aP�V�X��=u����:X��K�è���Z\;v^�����N�����߽��~��w��.M�h�a

this is just first four five lines. this is very large string of strange charters. I think issue with some UTF format. Not so sure. Help me please.

标签: php api file pdf
0条回答
登录 后发表回答