简体   繁体   中英

CURLOPT_FILE working on WAMP but not LAMP

I am a little new to PHP and curl. I setup a script in WAMP on my local machine. It will perform a curl and save the results to a .csv file. This same curl script is not working on a LAMP development environment that was recently setup for me. Instead, the resulting JSON is printed in the browser. Is there some kind of php extension I need to enable in the LAMP stack? here is the code:

$reportfileurl = 'https://www.googleapis.com/analytics/sampleurl';
$path = 'temp/temp.csv';
 $fp = fopen($path, 'w');
 $request = curl_init();
 curl_setopt($request, CURLOPT_URL, $reportfileurl);
 curl_setopt($request, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
 curl_setopt($request, CURLOPT_HTTPHEADER, array($authorization_header));
 //curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);
 curl_setopt($request, CURLOPT_FILE, $fp);
 curl_setopt($request, CURLOPT_SSL_VERIFYPEER, TRUE);
 curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 2);
 curl_setopt($request, CURLOPT_CAINFO, getcwd() . "/CAcerts/BuiltinObjectToken-EquifaxSecureCA.crt");
 $report_file = curl_exec($request);
 curl_close($request);
 fclose($fp);

On another note, since the curl request returns JSON i know i need to decode it before I can save the contents as a csv. I've found some posts about how to create an array from a JSON object, but I can't seem to be able to reference the contents inside the JSON object in an array so I wonder if part of the problem is with the difference in the curl handling?

cool. I figured out how to make a user group with permissions to add files/folders to /var/www and then i added the apache2 user 'www-data' to the group. instrcutions here

https://serverfault.com/questions/6895/whats-the-best-way-of-handling-permissions-for-apache2s-user-www-data-in-var

i am now able to write the .csv to the server. now I just need to decode the JSON into actual comma separated values!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM