SVKpneux Posted September 8, 2016 Share Posted September 8, 2016 Hi, I want to write php script to auto-save csv file from my supplier via API. My code: <?phpheader('Content-Type: text/csv');header('Content-Disposition: attachment; filename="sample.csv"');$curl = curl_init();curl_setopt_array($curl, array( CURLOPT_URL => "http://www.sample.com/folder/api/v1/", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "authorization: ApiKey xxx", "cache-control: no-cache", ),));$response = curl_exec($curl);$err = curl_error($curl);curl_close($curl);if ($err) { echo "cURL Error #:" . $err;} else { echo $response;} This works, but browser shows SAVE AS dialog...and I want save file directly to path (folder on my server) How can I do this? Thanks Peter Link to comment Share on other sites More sharing options...
tuk66 Posted September 8, 2016 Share Posted September 8, 2016 echo shows the response. Rather use fwrite or file_put_contents command. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now