i have write a code to export Data of an array to a csv file. But it only works, when i open the script in browser. I need a script that i can run in commando line because a cronjob. I can only show the last part of the script, the rest is for other things...
............. .............
$arrayCSV[]= array (
"id" => $templateID,
"state" => $templateState,
"price" => $templatePrice,
"exc_price" => $templateExc_price,
"downloads" => $templateDownloads,
"inserted_date" => $templateInsertedDate,
"update_date" => $templateUpdateDate,
"type" => $templateType,
"author" => $templateAuthor,
"live_preview_url" => $templateLivePreview,
"screenshot_big" => $templateScreenshotBig,
"screenshot_original" => $templateScreenshotOriginal,
"screenshot_german" => $templateScreenshotGerman,
"screenshot_responsive" => $templateScreenshotResponsive,
"keywords" => $templateKeywords,
"keywords_german" => $templateKeywordsGerman,
"categories" => $templateCategories,
"sources" => $templateSources,
"features" => $templateFeatures,
"template_name" => $templateName,
);
};
$csvExportFile = 'gettemplates.csv';
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=$csvExportFile");
$output = fopen("php://output", "w");
$header = array_keys($arrayCSV[0]);
fputcsv($output, $header);
foreach($arrayCSV as $row){
fputcsv($output, $row);
}
fclose($output);
it works in browser, but i need to change it, that it only writes a file from it...