Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

codefcuk's avatar

cURL with SPL Object is not working

I have a controller function which is calling an API to get some data and save in a file. $ch = curl_init('http://www.myserver.com/api/data'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_FAILONERROR, true); $filehandle = new SplFileObject(myfile.txt', 'w'); curl_setopt($ch, CURLOPT_FILE, $filehandle); curl_exec($ch);

if I use $filehandle = @fopen(myfile.txt', 'w'); It works like charm. but its giving error of "curl_setopt(): supplied argument is not a valid File-Handle resource" if i use SplFileObject.

Any suggestions?

0 likes
0 replies

Please or to participate in this conversation.