note 107667 deleted from function.curl-setopt by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 20:55:12 +0000 |
| Subject: | note 107667 deleted from function.curl-setopt by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217973@lists.php.net to get a copy of this message | ||
Note Submitter: wonderfish+php at gmail dot com
----
As of at least PHP 5.3.9, if you are continuing to use a cURL session handle after downloading a
file and closing the file handle, you will need to change CURLOPT_FILE back to stdout, and cannot
count simply on a side effect of CURLOPT_RETURNTRANSFER to do so, even if you are setting it. For
example:
<?php
$ch = curl_init();
$fh = fopen('/path/to/stored/file/example_file.dat', 'w');
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_URL, 'http://example.com/example_file.dat');
curl_exec($ch);
fflush($fh);
fclose($fh);
//must reset cURL file handle. Not doing so will cause a warning to be
//thrown and for cURL to default to output regardless
//for our example, we'll set return transfer.
curl_setopt($ch, CURLOPT_FILE, fopen('php://stdout', 'w'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, 'http://example.org/index.html');
$html = curl_exec($ch); //this will now work
?>