Curl not working as expected
in this code :
$url = 'http://example.com/someLARGE.file';
$path = 'test.txt';
$fp = fopen($path, 'w+');
$curl = curl_init();
//curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt ($curl, CURLOPT_URL, $url);
curl_exec($curl);
curl_close($curl);
fclose($fp);
The output is written to the browser and not to the file on the s开发者_StackOverflow社区erver :(
try with file_put_contents
$result = curl_exec($curl);
file_put_contents($file, $result,FILE_APPEND | LOCK_EX);
file_put_contents
is identical to calling fopen()
, fwrite()
and fclose()
successively to write data to a file.
in $fp = fopen($path, 'w+'); I did not have permissions to create/write to the file .
精彩评论