how to put stream php://temp content to html

213 views Asked by At

I got this from the API which is audio if I try it in postman.

enter image description here

the problem is I don't know how to retrieve it and put it in audio in html. I try to put the php://temp in src in audio html but it not work. because I used guzzle I try to use $response->getBody()->getContents() and I think it's the same as file_get_contents() in php but it shows nothing when I print it. please help in postman it can work but I don't know how to get it.

1

There are 1 answers

2
nay On

well in the lastest guzzlehttp document.you should iterate the body like this

$body = $response->getBody();
while (!$body->eof()) {
    echo $body->read(1024);
}

or better way save stream response to file

$body = $response->getBody();
file_put_contents('/webroot/file.mp3',$body);

then set html src

<audio src="file.mp3"></audio>