- if ( isset( $req['stream'] ) ) {
- // Don't just use CURLOPT_FILE as that might give:
- // curl_setopt(): cannot represent a stream of type Output as a STDIO FILE*
- // The callback here handles both normal files and php://temp handles.
- curl_setopt( $ch, CURLOPT_WRITEFUNCTION,
- function ( $ch, $data ) use ( &$req ) {
+ // This works with both file and php://temp handles (unlike CURLOPT_FILE)
+ $hasOutputStream = isset( $req['stream'] );
+ curl_setopt( $ch, CURLOPT_WRITEFUNCTION,
+ function ( $ch, $data ) use ( &$req, $hasOutputStream ) {
+ if ( $hasOutputStream ) {