P
P
podust2015-01-14 16:44:34
PHP
podust, 2015-01-14 16:44:34

How to save a PDF received in response to a CURL POST request?

The following task appeared:
1. I submit the necessary POST request to the resource
2. In response, it issues an HTTP page + PDF file.
3. I display CURL's response to the browser, and there is first an HTML file, and then a PDF binary.
The question is how to correctly extract this PDF from the answer and save it? Does CURL have any built-in mechanisms for this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
podust, 2015-01-14
@podust

Answer to your own question: use:

$pdf_file = fopen(путь до сохраняемого файла на диске, 'w+');
... все дела
curl_setopt($ch, CURLOPT_FILE, $pdf_file);
... все дела
fclose($pdf_file);

Suddenly someone like me will fall into a stupor :)

V
Valentin, 2015-01-14
@vvpoloskin

I do not know how in PHP, but in the console it is done like this:
curl -L <url>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question