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?
Please or to participate in this conversation.