php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74280 CURLOPT_FILE not work in curl_setopt_array
Submitted: 2017-03-21 09:11 UTC Modified: 2017-03-21 11:30 UTC
From: luutruong1992 at gmail dot com Assigned:
Status: Not a bug Package: cURL related
PHP Version: 5.6.30 OS: Linux
Private report: No CVE-ID: None
 [2017-03-21 09:11 UTC] luutruong1992 at gmail dot com
Description:
------------
I have try to downloading an file from remote URL but the file was empty while i using this code.
$url = 'http://some_url...';

$tempFile = 'output_file.data';
$fp = fopen($tempFile, 'w+');

$options = [
	CURLOPT_URL => $url,
	CURLOPT_FILE => $fp,
	CURLOPT_FOLLOWLOCATION => 1,
	CURLOPT_RETURNTRANSFER => 1
];

$ch = curl_init();
curl_setopt_array($ch, $options);

curl_exec($ch);
curl_close($ch);

fclose($fp);
?>

But when  I split CURLOPT_FILE to another method.
curl_setopt($ch, CURLOPT_FILE, $fp);

it is working property.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-21 11:30 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-03-21 11:30 UTC] requinix@php.net
CURLOPT_FILE (output goes to a file) and CURLOPT_RETURNTRANSFER (output goes to a string) are mutually exclusive.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC