0

I have a PHP script which make a curl request to remote server and get PDF file in response. If I store this response to file it is correct PDF file. Now I need to send thid file to browser as json cause initial request was ajax from browser. But dont know how to do it. The browser solution should be something like this https://stackoverflow.com/a/27563953/2092927 and I have it prepared. But I dont know how to send PDF from PHP as json. I know how to send it to download via common http request but dont know how to send it like json.

Does somebody know how to do it? Thanks for help.

Čamo
  • 3,863
  • 13
  • 62
  • 114
  • 1
    You don't send a file in JSON - JSON is text-only format. AJAX does not require the use of JSON, if that's what you're thinking. P.S. You technically _could_ embed a file inside a JSON object if you base64-encode it first, but it's not very efficient and I don't know why anyone would bother. – ADyson Jun 15 '22 at 13:21
  • I want it cause it takes a few times and want to display loading circle and catch possible exceptions on the way in json response. You thing base64 is enough for json + PDF? – Čamo Jun 15 '22 at 13:27
  • 1
    You could, but I wouldn't. And you don't need JSON to catch exceptions. – ADyson Jun 16 '22 at 15:00

0 Answers0