note 107667 modified in function.curl-setopt by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 20:21:10 +0000 |
| Subject: | note 107667 modified in function.curl-setopt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187786@lists.php.net to get a copy of this message | ||
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 ?>
--was--
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
?>
http://php.net/manual/en/function.curl-setopt.php