I am trying to save some JSON data to a local file. I am making a cUrl call to a REST service and doing the following:
$content = curl_exec( $ch );
curl_close( $ch );
$handle = fopen(time().'.txt','w');
fwrite($handle, $content);
print $content;
The file is created, but it is empty with the exception of the numeral 1. The JSON string does print out to screen without any problems, so the issue is not that I am getting an error. Any idea why this may be happening?
Answser:
I forgot to add the following to the curl call:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
fwrite() returns the number of bytes written, or FALSE on error.- Please post the result offwrite.